Sycophant.Response
(sycophant v0.4.2)
Copy Markdown
The result of an LLM call.
Contains the generated text or structured object, any tool calls requested
by the model, token usage statistics, and an opaque Context that enables
conversation continuation.
Continuing Conversations
Use response.context with Context.add/2 to continue the conversation:
{:ok, response} = Sycophant.generate_text("openai:gpt-4o-mini", messages)
ctx = response.context |> Context.add(Message.user("Tell me more"))
{:ok, follow_up} = Sycophant.generate_text("openai:gpt-4o-mini", ctx)Inspecting History
Use messages/1 to retrieve the full conversation history:
Response.messages(response)
#=> [%Message{role: :user, ...}, %Message{role: :assistant, ...}]Serialization
Responses implement Sycophant.Serializable for JSON persistence:
json = Sycophant.Serializable.Decoder.encode(response)
restored = Sycophant.Serializable.Decoder.decode(json)
Summary
Functions
Reconstructs a Response from a serialized map produced by Sycophant.Serializable.
Returns the full conversation message history from the response context.
Returns the first reasoning content text, if present.
Returns the response text.
Types
@type finish_reason() ::
:stop
| :tool_use
| :max_tokens
| :content_filter
| :recitation
| :error
| :incomplete
| :unknown
| nil
@type t() :: %Sycophant.Response{ context: Sycophant.Context.t(), finish_reason: finish_reason(), metadata: map(), model: String.t() | nil, object: map() | nil, raw: map() | nil, reasoning: Sycophant.Reasoning.t() | nil, text: String.t() | nil, tool_calls: [Sycophant.ToolCall.t()], usage: Sycophant.Usage.t() | nil }
Functions
Reconstructs a Response from a serialized map produced by Sycophant.Serializable.
@spec messages(t()) :: [Sycophant.Message.t()]
Returns the full conversation message history from the response context.
The list includes all user, assistant, system, and tool result messages exchanged during the conversation.
Returns the first reasoning content text, if present.
Returns the response text.