Sycophant.Agent (sycophant v0.4.2)

Copy Markdown

GenStateMachine-based agent that manages LLM conversations with tool execution, callbacks, statistics tracking, and telemetry.

States

  • :idle - Ready to accept new messages
  • :generating - Waiting for LLM response
  • :streaming - Waiting for LLM response with stream forwarding
  • :tool_executing - Executing tool calls from LLM response
  • :error - Last request failed, recoverable
  • :completed - Agent stopped by callback, no further requests accepted

Examples

{:ok, agent} = Sycophant.Agent.start_link("anthropic:claude-haiku-4-5-20251001")
{:ok, response} = Sycophant.Agent.chat(agent, "Hello!")
Sycophant.Agent.stop(agent)

Summary

Functions

Sends a message and waits synchronously for the response.

Sends a message asynchronously; response delivered via on_response callback.

Returns a specification to start this module under a supervisor.

Returns the current conversation context.

Starts an agent process linked to the caller.

Returns accumulated statistics for all turns.

Returns the current state of the agent.

Stops the agent process.

Types

agent()

@type agent() :: GenStateMachine.server_ref()

Functions

chat(agent, input, timeout \\ 30000)

@spec chat(
  agent(),
  String.t() | Sycophant.Message.t() | [Sycophant.Message.t()],
  timeout()
) ::
  {:ok, Sycophant.Response.t()} | {:error, term()}

Sends a message and waits synchronously for the response.

chat_async(agent, input)

@spec chat_async(
  agent(),
  String.t() | Sycophant.Message.t() | [Sycophant.Message.t()]
) ::
  :ok | {:error, term()}

Sends a message asynchronously; response delivered via on_response callback.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

context(agent)

@spec context(agent()) :: Sycophant.Context.t()

Returns the current conversation context.

start_link(model, opts \\ [])

@spec start_link(
  String.t() | nil,
  keyword()
) :: GenStateMachine.on_start()

Starts an agent process linked to the caller.

stats(agent)

@spec stats(agent()) :: Sycophant.Agent.Stats.t()

Returns accumulated statistics for all turns.

status(agent)

@spec status(agent()) :: atom()

Returns the current state of the agent.

stop(agent, reason \\ :normal)

@spec stop(agent(), term()) :: :ok

Stops the agent process.