What Are Agents?
In OpenFang, an agent is an autonomous execution unit with:- A unique identity (
AgentId— UUID v4) - A manifest declaring capabilities, tools, model config, and resources
- A session containing conversation history and memory
- A module (builtin:chat, wasm:module.wasm, python:script.py)
- A capability set enforced at the kernel level
- Respond to user messages
- Execute tool calls (file I/O, web search, shell commands, etc.)
- Spawn child agents
- Send messages to other agents
- Store and recall memories
- Run on schedules (continuous, periodic, proactive)
Agent Manifest Format
Every agent is defined by an AgentManifest (TOML or JSON):agent.toml
Manifest Fields Reference
Manifest Fields Reference
| Field | Type | Default | Description |
|---|---|---|---|
name | string | ”unnamed” | Human-readable agent name |
version | string | ”0.1.0” | Semantic version |
description | string | "" | What this agent does |
author | string | "" | Author identifier |
module | string | ”builtin:chat” | Execution module path |
schedule | ScheduleMode | reactive | Scheduling configuration |
model | ModelConfig | — | LLM model settings |
fallback_models | Vec<FallbackModel> | [] | Fallback chain |
resources | ResourceQuota | — | Token/cost limits |
priority | Priority | normal | Scheduling priority |
capabilities | ManifestCapabilities | — | Granted capabilities |
profile | Option<ToolProfile> | None | Named tool profile |
tools | HashMap<String, ToolConfig> | Tool-specific configs | |
skills | Vec<String> | [] | Skill allowlist (empty = all) |
mcp_servers | Vec<String> | [] | MCP server allowlist |
metadata | HashMap<String, Value> | Custom metadata | |
tags | Vec<String> | [] | Discovery tags |
routing | Option<ModelRoutingConfig> | None | Auto-model selection |
autonomous | Option<AutonomousConfig> | None | Guardrails for 24/7 agents |
workspace | Option<PathBuf> | None | Workspace directory |
exec_policy | Option<ExecPolicy> | None | Per-agent policy override |
tool_allowlist | Vec<String> | [] | Tool allowlist |
tool_blocklist | Vec<String> | [] | Tool blocklist |
Agent Lifecycle States
Running
Running
Agent is active and can receive messages. All subsystems are initialized:
- Session loaded from memory
- Capabilities granted
- Quota tracking active
- Event subscriptions registered
- Background loops started (if continuous/periodic/proactive)
Suspended
Suspended
Agent is paused (e.g., during daemon shutdown). State persisted to SQLite:
- Session saved
- Quota counters saved
- Background loops stopped
- Event subscriptions removed
Terminated
Terminated
Agent has been killed. Removed from:
- AgentRegistry
- CapabilityManager
- AgentScheduler
- EventBus subscriptions
- TriggerEngine
- Persistent storage (SQLite)
Spawn Flow
When you spawn a new agent:crates/openfang-kernel/src/kernel.rs:spawn_agent()
Spawn time: ~5ms on M1 Pro (2021). Includes full capability validation and SQLite persistence.
Capability Inheritance Validation
When an agent spawns a child, inheritance validation prevents privilege escalation:crates/openfang-types/src/capability.rs:validate_capability_inheritance()
Message Flow
When you send a message to an agent:crates/openfang-kernel/src/kernel.rs:send_message()crates/openfang-runtime/src/agent_loop.rs:run_agent_loop()
Message dispatch time: ~10ms (RBAC + quota check + routing). LLM latency is additional.
Capabilities System
OpenFang uses capability-based security: an agent can only perform actions it has been explicitly granted permission to do.Capability Types
crates/openfang-types/src/capability.rs
Pattern Matching Rules
| Pattern | Matches | Example |
|---|---|---|
| Exact match | Exact string | "api.openai.com:443" matches "api.openai.com:443" |
Wildcard * | Anything | "*" matches any host |
| Suffix wildcard | Ends with | "*.openai.com:443" matches "api.openai.com:443" |
| Prefix wildcard | Starts with | "/data/*" matches "/data/reports/q4.json" |
| Middle wildcard | Contains | "api.*.com" matches "api.openai.com" |
Enforcement Flow
Code reference:crates/openfang-kernel/src/capabilities.rscrates/openfang-runtime/src/tool_runner.rs
Security by Default
Capabilities are deny-by-default: if not explicitly granted, the operation is blocked. The LLM never sees tools it can’t invoke — they’re filtered out before the request.
Spawning and Messaging
Spawn a Child Agent
Agents can spawn children if they haveAgentSpawn capability:
- Parse the manifest
- Validate that child capabilities ⊆ parent capabilities
- Spawn the agent if valid
- Return the new
AgentId
Send a Message to Another Agent
Agents can message others if they haveAgentMessage(pattern) capability:
- Check
AgentMessage("summarizer")capability - Resolve
summarizerto anAgentId - Route the message
- Return the response
crates/openfang-runtime/src/tool_runner.rs:agent_message()
Inter-agent depth limit: 5 levels maximum. Prevents unbounded recursive agent-to-agent calls.
Scheduling Modes
Agents can run in four modes:Reactive
Reactive
Default mode. Agent only runs when it receives a message. No background loop.Use cases: Chatbots, on-demand assistants, API endpoints
Continuous
Continuous
Agent runs in a continuous loop, waking up periodically to check for work.Use cases: Monitoring, data ingestion, alerting
Periodic
Periodic
Agent runs on a cron-like schedule.Use cases: Daily reports, scheduled data processing, backups
Proactive
Proactive
Agent runs in response to system events (triggers).Use cases: Event-driven workflows, reactive automation
Agent Loop Stability
The agent loop includes multiple hardening layers:Loop Guard
Detects when an agent is stuck calling the same tool with the same parameters.(tool_name, params) to identify repetition.
Code reference: crates/openfang-runtime/src/loop_guard.rs
Session Repair
7-phase validation runs before each agent loop iteration:- Drop orphaned
ToolResultmessages (no matchingToolUse) - Remove empty messages
- Merge consecutive same-role messages
- Validate content blocks
- Fix missing tool_use_id references
- Ensure alternating user/assistant pattern
- Truncate if exceeds context window
crates/openfang-runtime/src/session_repair.rs
Tool Result Truncation
Enforces a 50,000 character hard cap on tool output. Truncated results include a marker showing original size:Tool Timeout
All tool executions are wrapped in a 60-second timeout. Tools that exceed this return a timeout error to the LLM instead of hanging.Max Continuations
MAX_CONTINUATIONS = 3 prevents infinite “Please continue” loops.
Stability Guidelines
Appended to every agent’s system prompt:crates/openfang-runtime/src/agent_loop.rs
Next Steps
Memory System
Learn about the 6-layer memory substrate
Hands System
Explore autonomous capability packages
Security Model
Understand capability-based security
Spawn Your First Agent
Step-by-step guide to creating an agent
