Sycophant.Context (sycophant v0.4.2)

Copy Markdown

Public conversation handle for multi-turn LLM interactions.

Context is a builder for conversation state. It holds message history, tools, streaming callbacks, and provider params. Model and response schema are per-call concerns and live outside the context.

Building a conversation

ctx = Context.new()
      |> Context.add(Message.system("You are helpful."))
      |> Context.add(Message.user("Hello!"))

Passing options

opts = Context.to_opts(ctx)

Summary

Functions

Appends one or more messages to the context.

Deserializes a context from a plain map.

Creates an empty context.

Creates a context from a message list or keyword opts.

Creates a context from messages and keyword opts.

Converts context fields into flat keyword opts for pipeline consumption.

Types

t()

@type t() :: %Sycophant.Context{
  messages: [Sycophant.Message.t()],
  params: map(),
  stream: (term() -> term()) | {term(), (term(), term() -> term())} | nil,
  tools: [Sycophant.Tool.t()]
}

Functions

add(ctx, messages)

@spec add(t(), Sycophant.Message.t() | [Sycophant.Message.t()]) :: t()

Appends one or more messages to the context.

from_map(data)

@spec from_map(map()) :: t()

Deserializes a context from a plain map.

new()

@spec new() :: t()

Creates an empty context.

new(messages)

@spec new([Sycophant.Message.t()] | keyword()) :: t()

Creates a context from a message list or keyword opts.

new(messages, opts)

@spec new(
  [Sycophant.Message.t()],
  keyword()
) :: t()

Creates a context from messages and keyword opts.

to_opts(ctx)

@spec to_opts(t()) :: keyword()

Converts context fields into flat keyword opts for pipeline consumption.