How syrin-labs/syrin-harness works
1. Repository shape
- This is a Python package (src/syrin) with a large set of runnable examples, docs, and tests.
- The package is organized as a production AI harness: a central Agent abstraction wraps model calls with budget, memory, guardrails, observability, sandboxing, and multi-agent orchestration.
- There is also a small TypeScript/Next.js playground/ app that acts as a UI boundary for serving and debugging agents.
2. Primary runtime boundary: Agent as the orchestration core
- The main execution path starts in syrin.agent and related internal modules.
- Agent.run() / async run flows through context building, prompt construction, model/provider resolution, tool execution, budget checks, guardrails, and response assembly.
- Most internal modules are split into private implementation files (_core, _run, _tool_exec, _context_builder, etc.), which keeps the public API thin and the execution pipeline centralized.
3. Model/provider layer
- src/syrin/model and src/syrin/providers isolate model abstraction from vendor specifics.
- Providers include OpenAI, Anthropic, OpenRouter, LiteLLM, Ollama, and a mock provider for testing.
- router/ adds model selection and modality-aware routing, so the agent can switch between models/providers based on cost, capability, or input type.
4. Budgeting and cost control
- budget/, cost/, ratelimit/, and budget_store/ implement the cost-control subsystem.
- The architecture supports preflight estimation, live enforcement, threshold callbacks, forecast/history, shared pools, and rate windows.
- Budget enforcement is not passive telemetry; it is a runtime gate that can stop, warn, or switch execution before another model call happens.
5. Memory and knowledge are separate retrieval systems
- memory/ manages persistent agent memory with backends such as SQLite, Postgres, Redis, Chroma, and Qdrant.
- knowledge/ is the RAG/document-integration layer: loaders ingest files and external sources, chunkers split content, stores persist embeddings/metadata, and grounding/verification support answer validation.
- The architecture keeps conversational memory, long-term user facts, and knowledge retrieval distinct so they can evolve independently.
6. Guardrails, security, and human-in-the-loop
- guardrails/, security/, and hitl/ form the safety boundary around model behavior.
- Guardrails cover PII, content, length, citations, fact verification, authority/capability checks, and prompt-injection defenses.
- HITL adds approval gates and session management where an agent needs explicit human confirmation before continuing.
7. Multi-agent orchestration
- swarm/, workflow/, rlm/, task/, agent_router.py, and agent/pipeline.py describe the multi-agent layer.
- The repo supports several coordination patterns: orchestrator, parallel, consensus, reflection, workflows, handoff, broadcast, spawn, and recursive decomposition.
- Shared budget pools, registry/pool abstractions, and memory buses provide the cross-agent control plane.
8. Sandboxed execution
- sandbox/ isolates code execution in subprocesses rather than the main Python process.
- The sandbox supports Python and bash execution, working directories/files, package preinstallation, timeout limits, and memory caps.
- This subsystem is the boundary between LLM-generated instructions and real execution, which is important for safety and reproducibility.
9. Serving and remote interfaces
- serve/, remote/, remote_config/, and mcp/ expose agents as services and interoperable endpoints.
- The package supports HTTP, CLI, and stdio serving, plus a bundled playground UI via static assets.
- MCP client/server support indicates the repo is also intended to integrate with external tool ecosystems and remote command/config negotiation.
10. Observability, debugging, and replay
- observability/, audit/, logging/, debug/, and hooks.py provide tracing and event instrumentation.
- The architecture emits typed lifecycle hooks across agent runs, tools, memory, budget events, sandbox execution, and swarm actions.
- A key design idea is that execution is observable without monkey-patching: the same events can feed logs, metrics, traces, audits, or a live debug UI.
11. Context, prompts, outputs, and types
- context/, prompt/, template.py, output_format/, response/, validation.py, and types/ manage the data shaping layer.
- Context assembly, compaction, runtime injection, structured outputs, and output-format conversion all sit between raw user input and model/provider calls.
- These modules are the main boundary where unstructured chat input becomes typed agent state and typed responses.
12. Extensibility surface
- tool/, capabilities/, generation/, embedding/, multimodal/, watch/, and resource/ are feature subsystems that plug into the core agent runtime.
- Tools are schema-driven, generation covers text/voice/media output, embeddings support memory/knowledge/routing, watches add triggers like cron/webhook/queue, and resource limits control run-time degradation.
- The repository is designed so new capabilities attach to the same agent execution pipeline rather than creating separate frameworks.
13. Tests and examples mirror the architecture
- tests/ is organized by subsystem and includes unit, integration, contract, e2e, and stress coverage.
- examples/ maps almost one-to-one to the main architecture areas: budget, memory, tools, loops, swarm, streaming, guardrails, observability, context, MCP, serving, routing, multimodal, knowledge, and checkpoints.
- For an architecture diagram, these examples are useful as concrete usage nodes, while the tests define the intended subsystem boundaries and invariants.
Main entry points: agent/_core.py Run Core · http.py Serve · observability/_core.py Observability · swarm/_core.py Swarm
Components 20
Core Runtime
Agent execution pipeline and shared shaping layers.
- Agent API · Thin public entrypoint for constructing and running agents.
src/syrin/agent/__init__.py - Run Core · Central run loop that coordinates prompt building, model calls, tools, and response assembly.
src/syrin/agent/_core.py - Context & Prompt · Builds runtime context, prompt structure, and injected state before model invocation.
src/syrin/agent/_context_builder.py - Tool Exec · Resolves and executes tool calls during an agent run.
src/syrin/agent/_tool_exec.py - Model Layer · Resolves model abstractions and vendor providers for agent execution.
src/syrin/agent/_model_provider.py
Safety & Control
Budget, guardrails, rate limits, and human approval gates.
- Budget Control · Preflight estimation, live enforcement, pools, and forecast/history for runtime cost control.
src/syrin/budget/_core.py - Rate Limits · Rate-window enforcement and retry behavior around calls.
src/syrin/ratelimit/_manager.py - Guardrails · Content, PII, authority, citation, fact, and prompt-injection checks.
src/syrin/guardrails/engine.py - HITL Gate · Human approval sessions and gating before continuing execution.
src/syrin/hitl/_gate.py
State & Retrieval
Memory, knowledge, and persistence systems.
- Memory · Conversational and long-term memory with pluggable backends.
src/syrin/memory/store.py - Knowledge RAG · Loaders, chunkers, stores, grounding, and verification for knowledge-backed answers.
src/syrin/knowledge/_core.py
Multi-Agent
Swarm, workflow, task, and routing coordination.
- Swarm · Multi-agent coordination, authority, handoff, broadcast, and control-plane state.
src/syrin/swarm/_core.py - Workflow · Structured multi-step execution with lifecycle, branching, and visualization.
src/syrin/workflow/_core.py - Router · Chooses models or providers based on capability, modality, or cost.
src/syrin/router/router.py
Interfaces
Serving, remote control, MCP, and playground UI.
- Serve · CLI, HTTP, stdio, discovery, and playground serving for agents.
src/syrin/serve/http.py - Remote Config · Remote negotiation, schema export, transport, and versioned configuration.
src/syrin/remote/_core.py - MCP · Model Context Protocol client/server and transport support.
src/syrin/mcp/server.py - Playground UI · Browser-based debugging and agent inspection interface.
playground/app/page.tsx
Observability
Logging, audit, hooks, tracing, and debug tooling.
- Observability · Hooks, tracing, metrics, audit, logging, and replay surfaces.
src/syrin/observability/_core.py - Debug UI · Pry/debug panels, state export, and live run inspection.
src/syrin/debug/_ui.py
Connections 24
- Agent API → Run Core: runs · Public API delegates into the centralized execution pipeline.
- Run Core → Context & Prompt: builds · Creates runtime context and prompt material before model invocation.
- Run Core → Model Layer: calls · Resolves a model/provider pair for the current run.
- Run Core → Tool Exec: executes · Runs tools and feeds results back into the agent loop.
- Run Core → Budget Control: checks · Enforces preflight and live budget constraints during execution.
- Run Core → Rate Limits: throttles · Applies request pacing and retry policy.
- Run Core → Guardrails: filters · Validates inputs, outputs, and intermediate decisions.
- Run Core → HITL Gate: escalates · Pauses for explicit human approval when required.
- Run Core → Memory: reads/writes · Stores and retrieves conversational and persistent memory.
- Run Core → Knowledge RAG: grounds · Pulls retrieved knowledge into the run for RAG and verification.
- Router → Model Layer: selects · Chooses the provider/model backing the run.
- Swarm → Run Core: orchestrates · Coordinates multiple agents through shared run mechanics.
- Workflow → Run Core: steps · Uses the agent runtime inside structured workflow steps.
- Swarm → Router: routes · Supports agent-to-agent and model routing decisions.
- Workflow → Budget Control: budgets · Propagates budget constraints across multi-step execution.
- Serve → Agent API: exposes · Wraps the agent API over HTTP, CLI, and stdio.
- Serve → Remote Config: negotiates · Loads remote configuration and service metadata.
- Serve → MCP: bridges · Offers interoperable MCP endpoints.
- Serve → Playground UI: ships · Serves the bundled playground UI as a front door.
- Observability → Run Core: instruments · Captures lifecycle events from agent execution.
- Observability → Swarm: traces · Records multi-agent actions and control-plane events.
- Debug UI → Observability: consumes · Builds inspection UI on top of the event and trace stream.
- Guardrails → Observability: emits · Guardrail decisions feed audit and trace systems.
- Memory → Knowledge RAG: complements · Distinct retrieval systems for conversational memory and document knowledge.