Packages
Elixir-native LangChain, LangGraph, and DeepAgents for traceable LLM apps: OTP workflows, tools, memory, human-in-the-loop, streaming, custom clients/adapters, minimal deps, and WeaveScope tracing.
Current section
Files
Jump to
Current section
Files
examples/structured_output_agent.exs
alias BeamWeaver.Core.ChatModel
alias BeamWeaver.Core.Message
defmodule BeamWeaver.Examples.StructuredOutputAgent.Model do
@behaviour ChatModel
defstruct []
def invoke(%__MODULE__{}, _messages, _opts) do
{:ok,
Message.assistant("",
tool_calls: [
%{id: "call-answer", name: "answer_schema", args: %{"answer" => "42"}}
]
)}
end
end
defmodule BeamWeaver.Examples.StructuredOutputAgent.AnswerSchema do
use BeamWeaver.Schema
title("answer_schema")
strict(true)
field(:answer, :string, required: true)
end
defmodule BeamWeaver.Examples.StructuredOutputAgent do
use BeamWeaver.Agent
model(%BeamWeaver.Examples.StructuredOutputAgent.Model{})
response_schema(BeamWeaver.Examples.StructuredOutputAgent.AnswerSchema,
name: "answer_schema",
strategy: :tool
)
end
{:ok, %{structured_response: %{"answer" => answer}}} =
BeamWeaver.Examples.StructuredOutputAgent.invoke(%{messages: [Message.user("answer")]})
IO.puts(answer)