Overview
The agent module providesMagpieAgent, a thin wrapper around Goose’s Agent with Magpie-specific defaults. It handles streaming LLM responses, tool execution (file edits, shell commands), and trace logging.
Core Types
MagpieAgent
Thin wrapper around Goose’s Agent with Magpie-specific defaults.
MagpieConfig
Configuration for creating a MagpieAgent.
LLM provider name (e.g. “claude-code”, “openai”)
Model name to use (e.g. “default”, “gpt-4”)
Maximum conversation turns before stopping
Directory for JSONL trace files. When set, all agent calls are traced
Methods
new()
Creates a new MagpieAgent with the given configuration.
Agent configuration
Returns configured agent instance
run()
Runs a prompt through the agent and returns the assistant’s text response.
Natural language prompt for the agent. Must not be empty.
Working directory for agent’s file/shell tools. Defaults to process CWD if None.
Name used for trace logging. Defaults to “agent” if None.
Returns the agent’s concatenated text response. Tool outputs are included in traces but not in the return value.
- Creates a Goose provider with the configured model
- Creates a hidden session with the working directory
- Streams agent events (text, tool requests, tool responses)
- Concatenates text fragments into final response
- Writes JSONL trace if
trace_diris configured
AgentEvent::Messagewith text content → concatenated into response- Tool requests/responses → logged in trace
- Thinking blocks → logged in trace
- Errors → logged in trace
Tool Access
The agent has access to Goose’s standard tools:- File operations: Read, write, edit files
- Shell commands: Execute arbitrary commands in
working_dir - Code analysis: Search, grep, understand codebases
working_dir sandbox. All tool use is automatically traced when trace_dir is set.
Trace Format
Whentrace_dir is configured, each agent call produces a JSONL file with:
Error Handling
Therun() method returns Result<String> and can fail for several reasons:
- Empty prompt: Prompt must not be empty (validated before execution)
- Provider creation failure: Invalid provider/model config
- Session creation failure: Working directory doesn’t exist
- Agent execution error: LLM API failure, tool execution errors
anyhow::Result with context for debugging.
Example with error handling:
Integration with Blueprint Engine
MagpieAgent is typically used through AgentStep in blueprints:
AgentStep.
Token Streaming
The agent streams tokens from the LLM as they arrive:- Tokens are concatenated without inserting newlines between fragments
- Tokens already carry their own spacing (e.g. ” the”, ” add”)
- This preserves single-line outputs like commit messages and branch slugs
Complete Example
Sandbox Behavior
In local sandboxes,MagpieAgent uses the full Goose agent loop with local tool execution.
In Daytona (remote) sandboxes, AgentStep dispatches to claude -p inside the sandbox instead of using MagpieAgent directly. This is handled automatically by the blueprint engine.
See Blueprint Engine: AgentStep for details.