Expand description
phi-agent: General-purpose AI Agent framework
Built on agent-base and agent-works, providing builder factory, renderer, config resolution, session management, and other infrastructure. Does not bundle any tools — tools are injected by consumers.
Re-exports§
pub use agent::CompressionConfig;pub use agent::PhiAgent;pub use agent::PhiAgentConfig;pub use agent::SummarizingMiddleware;pub use agent::base_agent_builder;pub use cli::ApprovalMode;pub use cli::AutoApprovalHandler;pub use config::LlmConfig;pub use config::resolve_llm_config;pub use event_log::event_to_jsonl;pub use event_log::event_to_value;pub use event_log::save_turn_log;pub use prompt::build_system_prompt;pub use prompt::build_system_prompt_cn;pub use render::EventRenderer;pub use render::JsonStreamRenderer;pub use render::NullRenderer;pub use render::OutputFormat;pub use render::create_renderer;pub use render::create_stdout_renderer;pub use session::SessionContext;
Modules§
- agent
- Agent construction and lifecycle management.
- cli
- CLI helpers — approval strategies and utilities shared across consumers.
- config
- Configuration resolution helpers.
- event_
log - Event log: serialize turn events to JSONL files.
- prompt
- render
- session
Structs§
- Agent
Builder - Agent
Runtime - Consecutive
Failure Recovery - Recovery strategy that tracks consecutive failures per tool and stops after a limit.
- Focus
- A focused LLM call.
- Focus
Context - Structured context for multi-field input scenarios.
- Focus
Output - Output wrapper for a Focus call.
- Open
AiClient - Plan
Item - A single step in a lightweight plan checklist.
- Reasoning
Config - Reasoning/thinking configuration, unifying reasoning/thinking parameters across vendors.
- Safety
Config - Safety configuration for agent runtime guardrails.
- Session
Id - Session
Metrics - Accumulated session metrics. Written incrementally to
session_metrics.jsonat the end of each turn. - Session
Summary - Lightweight summary returned by
list_all(). - Tool
Context - Tool
Metadata - Machine-readable metadata for a registered tool — origin, version, and runtime requirements in a stable shape consumers can inspect without parsing the LLM-facing definition JSON.
- Tool
Output - Turn
Fact Middleware - Turn fact summary middleware — injects structured facts from the previous turn’s tool results into the next user message.
- Turn
Metrics - Per-turn metrics — one per LLM interaction.
- Turn
Tool Limit Middleware - Middleware that enforces a hard limit on tool calls per turn.
- Update
Plan Tool - A lightweight tool that records and displays a plan checklist to the user.
Enums§
- Agent
Error - Focus
Error - Error type for Focus calls.
- Plan
Step Status - Lightweight plan step status — display-only, no execution semantics.
- Reasoning
Effort - Reasoning intensity/depth enumeration.
- RunOutcome
- The final outcome of an Agent run
- Runtime
Event - Unified runtime event — the single event type for both internal and external consumers (frontends, CLIs, tests).
- Session
Outcome - Outcome of a session (the entire conversation).
- Tool
Control Flow - Turn
Outcome - Outcome of a single turn (one LLM interaction).
Traits§
- Approval
Handler - Trait for handling tool approval requests.
- Focus
Input - Input for a Focus call — either a simple string or a structured context.
- LlmClient
- Tool
Functions§
- list_
all_ metrics - List all session summaries by scanning the sessions directory.
Reads each
session_metrics.jsonand extracts summary fields. - load_
metrics - Load session metrics from
session_metrics.jsonin a session directory. - save_
metrics - Incrementally write session metrics to
session_metrics.json. Overwrites the file on each call — safe for per-turn writes. - try_
load_ metrics - Try to load session metrics, returning
Noneif the file doesn’t exist.