How go-kratos/blades works
Purpose and entry points
Blades is a Go framework for building multimodal LLM agents: model invocation, tool calling, memory, middleware, streaming, and composable workflows. Library consumers construct agents through the public package rooted at agent.go, then execute them via runner.go. The standalone “blades” CLI has a separate module and entry point at cmd/blades/main.go; documentation generation is another executable at cmd/docs/main.go.
Core agent execution
The primary runtime abstraction is Agent, implemented by the framework agent and exercised through a Runner. An invocation enters the agent with user messages/instructions, builds model context, invokes the configured model (potentially streaming), processes tool interactions, and yields messages or errors. Core contracts and orchestration are concentrated in:
• agent.go
• runner.go
• core.go
Model and multimodal boundary
ModelProvider isolates framework request/message types from vendor-specific APIs. The core model contract lives in model.go; adapters translate it for OpenAI, Anthropic/Claude, and Gemini, including image/audio capabilities where supported. This is the primary external-service boundary, driven by provider credentials and endpoints supplied by callers.
• model.go
• contrib/openai/chat.go
• contrib/anthropic/claude.go
Tools, skills, and MCP integration
Tools expose schemas plus handlers so a model can request external actions; tool middleware and resolution provide a controlled execution boundary. Skills are loaded from directories or embedded files and injected into agent prompting/toolsets. MCP support adds client, transport, configuration, and endpoint resolution for external tool servers.
• tools/tool.go
• skills/loader.go
• contrib/mcp/client.go
Context, sessions, and memory
Conversation state is represented by messages, invocations, and sessions. Agents can persist/search memory through a pluggable memory interface; the bundled implementation is in-memory. Context strategies manage prompt size by windowing or summarizing accumulated history, forming the key boundary between unbounded conversation state and finite model context.
• session.go
• memory/memory.go
• context/summary/summary.go
Middleware and execution controls
Runner and tool middleware wrap execution for cross-cutting behavior such as confirmation and retries. Streaming uses a generator abstraction, allowing callers and channels to consume incremental model output. Evaluation support provides criteria-based assessment of agent results.
• middleware.go
• middleware/retry.go
• stream/stream.go
Workflow composition
The graph subsystem executes task graphs with state, retries, middleware, and checkpoints; the higher-level flow package supplies sequential, parallel, routing, loop, and deep-agent compositions. Recipes declaratively load, validate, template, and build agent/workflow definitions from YAML-like specifications.
• graph/executor.go
• flow/sequential.go
• recipe/loader.go
CLI application and delivery channels
The separate cmd/blades application bootstraps workspaces, configures model registries and runtime services, and runs chat, daemon, cron, memory, and operational commands. It supports local CLI interaction plus Lark and Weixin channel adapters; cron enables scheduled/heartbeat execution. Workspace templates establish agent identity, memory, tool, and instruction files.
• cmd/blades/cmd/root.go
• cmd/blades/internal/app/runner.go
• cmd/blades/internal/channel/lark/channel.go
Components 22
Framework Runtime
- Public Agent API · Consumer entry point for constructing agents.
agent.go - Runner · Executes agent invocations and returns results or streams.
runner.go - Agent Core · Builds context, invokes models, and coordinates tool turns.
core.go - ModelProvider · Vendor-neutral model and multimodal request boundary.
model.go - Sessions & Messages
session.go - Memory Interface · Persists and searches agent memory.
memory/memory.go - Context Strategy · Summarizes accumulated history to fit model context.
context/summary/summary.go - Execution Middleware · Wraps runner and tool execution.
middleware.go - Retry Middleware
middleware/retry.go - Streaming · Delivers incremental model output to callers or channels.
stream/stream.go
Provider & Tool Integrations
- Tools · Schemas and handlers for model-requested actions.
tools/tool.go - Skills Loader · Loads directory or embedded skills into agents.
skills/loader.go - MCP Client · Resolves and connects to MCP tool servers.
contrib/mcp/client.go - OpenAI Adapter
contrib/openai/chat.go - Anthropic Adapter
contrib/anthropic/claude.go
Composition & Definitions
- Graph Executor · Runs task graphs with state, retries, middleware, and checkpoints.
graph/executor.go - Flow Composition · Provides sequential, parallel, routing, loop, and deep-agent flows.
flow/sequential.go - Recipe Loader · Loads and builds agent or workflow definitions.
recipe/loader.go
Blades CLI
- Blades CLI Entry · Separate module entry point.
cmd/blades/main.go - CLI Commands · Chat, daemon, cron, memory, and operational commands.
cmd/blades/cmd/root.go - CLI App Runner · Configures workspace, model registries, and runtime services.
cmd/blades/internal/app/runner.go - Lark Channel
cmd/blades/internal/channel/lark/channel.go
Connections 21
- Public Agent API → Runner: executed by
- Runner → Agent Core: orchestrates
- Runner → Execution Middleware: wrapped by
- Execution Middleware → Retry Middleware: includes
- Agent Core → Sessions & Messages: reads and updates
- Agent Core → Memory Interface: persists/searches
- Agent Core → Context Strategy: compacts history with
- Agent Core → ModelProvider: invokes
- Agent Core → Tools: resolves tool calls
- Agent Core → Skills Loader: injects
- Runner → Streaming: emits incremental output
- ModelProvider → OpenAI Adapter: implemented by
- ModelProvider → Anthropic Adapter: implemented by
- Tools → MCP Client: extends via
- Flow Composition → Graph Executor: executes through
- Recipe Loader → Public Agent API: builds
- Recipe Loader → Flow Composition: builds
- Blades CLI Entry → CLI Commands: starts
- CLI Commands → CLI App Runner: dispatches to
- CLI App Runner → Runner: runs agents with
- CLI App Runner → Lark Channel: connects channel