glean/agent

Types

An agent definition. Generic over deps — the dependency type threaded through to tools during execution.

pub type Agent(deps) {
  Agent(
    provider: provider.Provider,
    system_prompts: List(String),
    tools: tool.Toolset(deps),
    settings: provider.ModelSettings,
    tool_choice: provider.ToolChoice,
    max_steps: Int,
    response_format: provider.ResponseFormat,
    parallel_tool_calls: Bool,
  )
}

Constructors

  • Agent(
      provider: provider.Provider,
      system_prompts: List(String),
      tools: tool.Toolset(deps),
      settings: provider.ModelSettings,
      tool_choice: provider.ToolChoice,
      max_steps: Int,
      response_format: provider.ResponseFormat,
      parallel_tool_calls: Bool,
    )

    Arguments

    provider

    The provider to use for generation

    system_prompts

    System prompt(s) prepended to every conversation

    tools

    Available tools

    settings

    Default model settings

    tool_choice

    Tool choice strategy

    max_steps

    Maximum number of generate-tool-loop steps (safety limit)

    response_format

    Plain text, or JSON (optionally constrained by a schema). With a schema, the final answer is validated against it.

    parallel_tool_calls

    Run several tool calls from one model response concurrently (default: True). Results are always returned in the model’s order.

Values

pub fn from(model: model.Model) -> Agent(deps)

Create an agent from a type-safe Model. The Model carries both the provider and validated settings.

pub fn json_output(
  agent: Agent(deps),
  schema schema: option.Option(schema.Schema),
  name name: option.Option(String),
) -> Agent(deps)

Ask for JSON output. With a schema, the provider is asked to follow it (where the API supports schemas) and the final answer is validated against it: a mismatch fails the run with OutputValidationError.

agent.from(model)
|> agent.json_output(schema: Some(person_schema), name: Some("person"))
pub fn max_steps(agent: Agent(deps), max: Int) -> Agent(deps)

Set the maximum number of agent loop steps.

pub fn new(provider: provider.Provider) -> Agent(deps)

Create a new agent with the given provider. All other fields get sensible defaults.

pub fn sequential_tool_calls(agent: Agent(deps)) -> Agent(deps)

Run tool calls one after another instead of concurrently. Use this when your tools must not run at the same time (e.g. they share a resource).

pub fn settings(
  agent: Agent(deps),
  settings: provider.ModelSettings,
) -> Agent(deps)

Set model settings.

pub fn system(agent: Agent(deps), prompt: String) -> Agent(deps)

Add a system prompt to the agent.

pub fn tool_choice(
  agent: Agent(deps),
  choice: provider.ToolChoice,
) -> Agent(deps)

Set the tool choice strategy.

pub fn tools(
  agent: Agent(deps),
  tools: tool.Toolset(deps),
) -> Agent(deps)

Set the tools available to this agent.

✨ Search Document