Packages

A Gleam library for building and orchestrating agents on the BEAM.

Current section

Files

Jump to
pig src pig@agent@effect.erl
Raw

src/pig@agent@effect.erl

-module(pig@agent@effect).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/pig/agent/effect.gleam").
-export_type([effect/1]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Effect types for the sans-IO agent core.\n"
"\n"
" Effects are declarations of intent — the core describes what it wants\n"
" done, and a runtime interprets these effects against the real world.\n"
"\n"
" Two effects cover the entire agent loop:\n"
" `CallProvider` — send messages to the LLM\n"
" `ExecuteTools` — run tool calls\n"
"\n"
" The `on_response` / `on_results` callbacks wrap results into the\n"
" core's message type, closing the loop without the core knowing\n"
" how the effects were executed.\n"
).
-type effect(HPT) :: {call_provider,
list(pig@ai@message:message()),
list(pig@ai@tool_definition:tool_definition()),
fun(({ok, pig@ai@provider:inference_result()} |
{error, pig@ai@error:ai_error()}) -> HPT)} |
{execute_tools,
list(pig@ai@message:tool_call()),
fun((list({pig@ai@message:tool_call(),
{ok, gleam@json:json()} | {error, pig@tool:tool_error()}})) -> HPT)}.