Anda Framework Documentation

repository·main·Indexed 19 days ago

https://github.com/ldclabs/anda

A Rust-based framework for building composable AI agent runtimes. Anda enables the orchestration of models, tools, and memory into unified workflows through components including anda_core for shared traits and data models, anda_engine for runtime management, and anda_engine_server for a stateless HTTP front-end. It features a label-based model routing system with adapters for OpenAI, Anthropic, and Gemini, as well as a command-line interface (anda_cli) for executing agents and generating cryptographic bytes.

Tokens
49.8K
Snippets
128
Records
210
Agent score
64%

What's inside Anda

  1. Overview of anda_web3_client

    main
    anda_web3_client is a Rust SDK designed for Web3 integration in non-TEE (Trusted Execution Environment) environments. It provides a Web3ClientFeatures implementation for Anda agents, allowing them to interact with the Internet Computer (ICP) without requiring specialized TEE hardware. It uses an ic-agent-based client and local key derivation to back the engine's Web3 context.
  2. What is Anda?

    main

    Anda is a composable AI agent runtime framework built in Rust. It is designed to combine models, tools, memory, and other agents into a single runtime. The framework emphasizes composability, type-safe extension points, asynchronous execution, and practical runtime control.

    Key capabilities include:

    • Registering agents and tools.
    • Routing model requests via capability labels.
    • Calling local or remote functions.
    • Isolating context state.
    • Adding persistence and memory layers as needed.
  3. Overview of the Anda AI Agent Runtime Framework

    main

    Anda is a composable AI agent runtime framework built in Rust. It allows developers to combine models, tools, memory, and other agents into a single runtime. The framework focuses on composability, type-safe extension points, asynchronous execution, and controllable runtime scheduling.

    The core engine enables developers to:

    • Register agents and tools.
    • Route model requests based on capability tags.
    • Call local or remote functions.
    • Isolate context state.
    • Integrate optional persistence and memory layers.
  4. Overview of anda_engine_server

    main

    The anda_engine_server is a stateless HTTP front-end designed to expose one or more Anda engines. It acts as a thin proxy that authenticates callers and forwards typed requests to a target engine. It does not manage sessions, tools, or persistence; those responsibilities reside in the anda_engine runtime.

    Key responsibilities include:

    • HTTP request routing and codec negotiation (CBOR/JSON).
    • Authentication via ICP SignedEnvelope verification and optional bearer CWT tokens.
    • Dispatching agent and tool requests to the engine.
  5. Overview of the Anda framework

    main

    Anda is a Rust framework designed for building composable AI agent runtimes. It allows developers to combine models, tools, memory, and other agents into a single, unified runtime. The framework focuses on composability, type-safe extension points, asynchronous execution, and practical runtime control.

    Key capabilities include:

    • Model Routing: Routing requests through labeled tiers (e.g., primary, pro, flash, lite) using common request/output contracts.
    • Runtime Orchestration: Managing iterative model turns, tool calls, usage accounting, and long-running session handoffs via a CompletionRunner.
    • Scoped Execution: Providing isolated state and capabilities (cache, object storage, HTTP, cancellation) through BaseCtx and AgentCtx.
    • Discovery-aware Tools: Allowing agents to survey tool bundles using tools_groups and expand them with tools_select on demand.
  6. Core Concepts of the Anda Runtime

    main

    Anda's architecture is built around several key abstractions:

    • Composable Agents and Tools: Registered via stable traits and function definitions, allowing components to form complex workflows.
    • Model Routing: The engine routes completion requests using capability tags like primary, pro, flash, and lite. Provider adapters abstract the specific model implementation.
    • Runtime Orchestration (CompletionRunner): Manages the lifecycle of model interactions, including iterating through turns, executing tool calls, calling agents, accumulating usage, summarizing artifacts, handling steering/follow-up messages, cancellation, and managing long-session continuation handoffs.
    • Isolated Execution Contexts: BaseCtx and AgentCtx provide isolated state, cache, object storage, HTTP calls, signed calls, cancellation, and child contexts for each agent or tool.
    • Extensible Memory and Skills: Supports extensions for conversation storage, memory tools (based on KIP), filesystem, shell, fetch, notes, todos, and file-driven skills.
    • Tool Discovery: Supports a two-step discovery process where agents can browse tools_groups (static tools, dynamic providers, or MCP servers) and then use tools_select to expand a specific group when a schema is required.
  7. How Tools work in Anda

    main

    A tool implements the Tool<C> trait, utilizing associated types Args and Output for strong typing.

    Workflow:

    1. The runtime receives a raw JSON tool call.
    2. The runtime deserializes the JSON into the tool's Args type.
    3. The tool's call method is executed.
    4. The Output is serialized back to JSON for the runtime.

    Resource Management: Tools can declare supported resource tags. When a tool is called, the runtime identifies matching resources from the request resource list, removes them from the general list, and passes them specifically to the tool.

  8. Configure and route Models

    main

    The Models registry is thread-safe and uses label-based routing. You can register concrete Model values under labels like primary, pro, flash, or lite. This allows agents to request a model by label (e.g., primary) while the underlying provider can be changed without updating agent logic.

    Built-in adapters:

    • openai: OpenAI-compatible Responses API style.
    • anthropic: Anthropic Messages API.
    • gemini: Google Gemini.

    Custom providers: Implement CompletionFeaturesDyn and wrap with Model::with_completer.

  9. Understand the Anda Engine Runtime Architecture

    main

    The Anda Engine is a runtime that manages the lifecycle of AI agents and tools. Its core responsibilities include validating callers, creating isolated contexts, scheduling agents and tools, routing model requests, and handling tool calls.

    Key architectural layers include:

    • Engine Boundary: Managed by Engine (holds runtime state, default agents, hooks) and configured via EngineBuilder (registers tools, agents, models, stores, etc.). EngineCard is used to publish exported definitions for remote discovery.
    • Access Control & Observability: Uses Management for visibility (Private, protected, public) and Hooks (on_agent_start/end, on_tool_start/end) to observe or modify outputs. Cancellation is handled via root and child tokens passed through contexts.
    • Registry: Contains AgentSet (local agents), ToolSet / ToolProviderSet (static tools and runtime providers), and RemoteEngines (remote functions routed via RA_ and RT_ prefixes).
    • Execution (Runner): AgentCtx combines BaseCtx with models, tools, and routing helpers. CompletionRunner iterates through model turns, executes tool calls, and generates final output. SubAgent sessions support both synchronous calls and background sessions with hooks.
    • BaseCtx Capabilities: Provides scoped state (request meta, elapsed time), isolated Store and cache via context paths, and external call capabilities (HTTP, signed RPC, key derivation).
    • Model Routing: Uses Models for tag-based routing (e.g., pro, flash, lite) and Adapters (OpenAI-compatible, Anthropic, Gemini, or custom CompletionFeaturesDyn providers).
    • Storage & Extensions: Includes built-in tools (filesystem, shell, fetch, etc.) and optional persistence via Memory (AndaDB) and ObjectStore (in-memory, local, or cloud).
  10. Understand the Anda Engine request lifecycle

    main

    The Anda Engine operates on an iterative completion loop managed by a CompletionRunner. When an agent_run is triggered, the following sequence occurs:

    1. Validation & Guarding: The Engine validates the request and uses a Guard to check visibility/permissions.
    2. Context Initialization: An AgentCtx is created to manage the lifecycle and resources.
    3. Agent Execution: The Agent starts its run loop. The AgentCtx delegates completion requests to the CompletionRunner.
    4. Iterative Completion Loop:
      • The Runner resolves the model via Models (using a label or default).
      • The Model returns an AgentOutput containing content, usage, and potentially tool_calls.
      • Tool Execution: If tool_calls are present, the Runner resolves them via a Registry (identifying them as local, remote, or subagent) and executes them.
      • Feedback Loop: Tool outputs are appended to the context and fed back into the next model request.
      • This loop continues until a final output, failure, or cancellation occurs.
    5. Finalization: The Engine triggers on_agent_end hooks, transforms the output, and returns the final AgentOutput to the caller.
    @startuml
    title Anda Engine agent_run and completion loop
    # ... (Sequence diagram logic) ...
    @enduml
  11. Understand the Anda Engine request and completion loop

    main

    The Anda Engine operates on an iterative completion loop managed by a CompletionRunner. When an agent_run is submitted, the engine validates the request, checks visibility via the Guard (Management + Hooks), and initializes an AgentCtx.

    The Iteration Loop:

    1. Model Turn: The CompletionRunner resolves the requested model (via Models routing) and sends a CompletionRequest to the model adapter (e.g., OpenAI, Anthropic, Gemini).
    2. Tool/Agent Resolution: If the model returns tool_calls, the runner resolves them against registries using specific prefixes:
      • RA_: Remote Agent
      • RT_: Remote Tool
      • SA_: SubAgent
      • (Unprefixed): Local Tool or Agent
    3. Execution: Depending on the type, the runner executes the call via Local::call, Agent::run, https_signed_rpc for remote calls, or spawns a SubAgent session runner for background tasks.
    4. Feedback: Tool outputs are accumulated and fed back into the next model turn. This continues until the model provides a final output, a failure occurs, or the process is cancelled.
    5. Steering: The runner can insert user content at safe boundaries or prune unanswered tool history to manage context size.
    @startuml
    title Anda Engine agent_run and completion loop
    # ... (Sequence diagram logic) ...
    @enduml
  12. Use AgentCtx and CompletionRunner for execution

    main

    Agent execution is driven by two primary abstractions:

    1. AgentCtx: A specialized context that combines BaseCtx capabilities (scoped state, cache, store, HTTP, signed RPC) with model routing, tools, agents, and subagents. It provides the environment in which an agent operates.
    2. CompletionRunner: The execution engine that iterates through model turns, executes necessary tool calls, accumulates usage/artifacts, and returns the final output to the caller.

    For background tasks, SubAgent sessions (SA_ workers) can be used to support blocking calls or background sessions with progress and final hooks.