Skip to content

Runtime Engine

The Runtime Engine is the central orchestrator that bootstraps agents from declarative YAML configuration and manages their lifecycle. It lives in astromesh/runtime/engine.py.

AgentRuntime is the top-level entry point for the platform. It scans configuration directories, parses agent definitions, assembles fully-wired Agent instances, and exposes a single execution method.

AgentRuntime(config_dir: str | Path = "config/")
ParameterTypeDefaultDescription
config_dirstr | Path"config/"Root configuration directory containing agents/, channels.yaml, and other config files

runtime.run(agent_name, query, session_id)

Section titled “runtime.run(agent_name, query, session_id)”

Execute a named agent with a user query.

async def run(
agent_name: str,
query: str,
session_id: str | None = None,
) -> AgentResponse
ParameterTypeRequiredDescription
agent_namestrYesName of the agent as defined in YAML (metadata.name)
querystrYesUser input text
session_idstr | NoneNoSession identifier for memory continuity. Auto-generated if omitted

Returns: AgentResponse containing the agent’s reply text, tool call logs, token usage, and timing metadata.

Execution pipeline: Query received -> input guardrails -> build memory context -> render Jinja2 prompt -> orchestration pattern (ReAct/PlanAndExecute/etc.) -> model router -> tool calls -> output guardrails -> persist memory -> return response.

Retrieve a loaded Agent instance by name.

def get_agent(agent_name: str) -> Agent

Raises AgentNotFoundError if the agent is not loaded.

Return a list of all loaded agent names.

def list_agents() -> list[str]
config/
├── agents/
│ ├── assistant.agent.yaml ─┐
│ ├── researcher.agent.yaml ├── Scanned at bootstrap
│ └── support.agent.yaml ─┘
├── channels.yaml ── Channel adapters config
└── runtime.yaml ── Global runtime settings
┌──────────────────────────────────────────────────────────────────────┐
│ Bootstrap │
│ │
│ 1. Read runtime.yaml (global settings) │
│ 2. Scan agents/*.agent.yaml │
│ 3. For each agent YAML: │
│ a. Parse & validate schema │
│ b. Create ModelRouter (primary + fallback providers) │
│ c. Create MemoryManager (backends per memory type) │
│ d. Create ToolRegistry (internal, MCP, webhook, RAG) │
│ e. Create PromptEngine (load Jinja2 templates) │
│ f. Create GuardrailsEngine (input + output guards) │
│ g. Create OrchestrationPattern (ReAct, PlanAndExecute, etc.) │
│ h. Assemble Agent instance │
│ 4. Load channel adapters │
│ 5. Runtime ready │
└──────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────┐
│ Agent Instances │
│ │
│ assistant ────── Agent(router, memory, tools, prompts, guards, orch) │
│ researcher ────── Agent(router, memory, tools, prompts, guards, orch) │
│ support ────── Agent(router, memory, tools, prompts, guards, orch) │
└─────────────────────────────────────────────────────────────────────────┘

Each agent transitions through four states:

┌──────┐ ┌───────┐ ┌───────────┐ ┌──────┐
│ Load │ ──▶ │ Ready │ ──▶ │ Executing │ ──▶ │ Idle │
└──────┘ └───────┘ └───────────┘ └──────┘
▲ │
└───────────────────────────────┘
StateDescription
LoadYAML parsed, services assembled, agent instance created. Occurs once at bootstrap
ReadyAgent is fully wired and available to handle requests. All providers have passed health checks
ExecutingAgent is actively processing a query through the execution pipeline
IdleExecution complete, agent returns to ready state waiting for the next request

An agent can handle multiple concurrent requests. Each request transitions independently through Executing -> Idle while the agent itself remains in Ready state.

Each agent file must conform to the following top-level structure:

apiVersion: astromesh/v1
kind: Agent
metadata:
name: my-agent
description: "Agent description"
spec:
identity: { ... }
model: { ... }
prompts: { ... }
orchestration: { ... }
tools: [ ... ]
memory: { ... }
guardrails: { ... }
permissions: { ... }
FieldRequiredDescription
apiVersionYesMust be astromesh/v1
kindYesMust be Agent
metadata.nameYesUnique agent identifier (used in API paths and runtime.run())
metadata.descriptionNoHuman-readable description
spec.identityYesAgent persona (name, role, personality traits)
spec.modelYesPrimary model, fallback model, routing strategy
spec.promptsYesJinja2 system prompt template and variables
spec.orchestrationYesPattern name, max iterations, timeout
spec.toolsNoList of tools the agent can use
spec.memoryNoMemory types and backend configuration
spec.guardrailsNoInput and output guardrail rules
spec.permissionsNoAllowed actions and resource limits
ErrorCauseBehavior
AgentNotFoundErrorrun() called with unknown agent nameRaised immediately
ConfigValidationErrorInvalid YAML schema at bootstrapAgent skipped, warning logged, other agents still load
ProviderUnavailableErrorAll providers (primary + fallback) fail health checkAgent loads but requests fail until a provider recovers