Skip to content

Commit

Permalink
chore: update documents
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Feb 16, 2025
1 parent 28918b6 commit 0a18867
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ members = [
]

[workspace.package]
description = "Anda is a framework for AI agent development, designed to build a highly composable, autonomous, and perpetually memorizing network of AI agents."
description = "Anda is an AI agent framework built with Rust, powered by ICP and TEEs."
repository = "https://github.com/ldclabs/anda"
homepage = "https://github.com/ldclabs/anda"
keywords = ["ai-agent", "icp", "tee"]
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# `Anda`

> 🤖 A framework for AI agent development, designed to build a highly composable, autonomous, and perpetually memorizing network of AI agents.
> 🤖 An AI agent framework built with Rust, powered by ICP and TEEs.
## 🌍 README Translations

[English readme](./README.md) | [中文说明](./README_CN.md)

## 🤖 Introduction

`Anda` is an innovative agent development framework designed to build a highly composable, autonomous, and permanently memory-enabled AI agent network. By connecting agents across various industries, Anda aims to create a super AGI system, advancing artificial intelligence to higher levels.
Anda is an AI agent framework built with Rust, featuring ICP blockchain integration and TEE support.
It is designed to create a highly composable, autonomous, and perpetually memorizing network of AI agents.
By connecting agents across various industries, Anda aims to create a super AGI system, advancing artificial intelligence to higher levels.

![Anda Diagram](./anda_diagram.webp)

Expand Down
6 changes: 4 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# `Anda`

> 🤖 一个专为 AI 智能体开发设计的框架,致力于构建高度可组合、自主运行且具备永久记忆能力的 AI 智能体网络
> 🤖 一个基于 Rust 构建的 AI 智能体框架,由 ICP 区块链和 TEE 环境赋能
## 🌍 说明文档翻译

[English readme](./README.md) | [中文说明](./README_CN.md)

## 🐼 简介

`Anda` 是一个创新的智能体开发框架,旨在构建一个高度可组合、自主性强且具有永久记忆的 AI 智能体网络。通过连接各行各业的智能体,Anda 致力于打造一个超级 AGI 系统,推动人工智能向更高层次发展。
Anda 是一个基于 Rust 构建的 AI 智能体框架,集成了 ICP 区块链并支持 TEE 环境。
它旨在构建一个高度可组合、自主运行且具备持续记忆能力的 AI 智能体网络。
通过连接跨行业的智能体,Anda 致力于打造一个超级 AGI 系统,推动人工智能向更高层次发展。

![Anda Diagram](./anda_diagram.webp)

Expand Down
2 changes: 1 addition & 1 deletion anda_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "anda_core"
description = "Core types and traits for Anda -- a framework for AI agent development."
description = "Core types and traits for Anda -- an AI agent framework built with Rust, powered by ICP and TEEs."
repository = "https://github.com/ldclabs/anda/tree/main/anda_core"
publish = true
version = "0.4.0"
Expand Down
2 changes: 1 addition & 1 deletion anda_engine/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "anda_engine"
description = "Agents engine for Anda -- a framework for AI agent development."
description = "Agents engine for Anda -- an AI agent framework built with Rust, powered by ICP and TEEs."
repository = "https://github.com/ldclabs/anda/tree/main/anda_engine"
publish = true
version = "0.4.1"
Expand Down
30 changes: 30 additions & 0 deletions examples/icp_ledger_agent/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,27 @@ use anda_icp::ledger::{BalanceOfTool, ICPLedgers, TransferTool};
use candid::Principal;
use std::{collections::BTreeSet, sync::Arc};

/// An AI agent implementation for interacting with ICP blockchain ledgers.
/// This agent provides capabilities to check balances and transfer ICP tokens
/// using the provided tools.
#[derive(Clone)]
pub struct ICPLedgerAgent {
ledgers: Arc<ICPLedgers>,
tools: Vec<&'static str>,
}

impl ICPLedgerAgent {
/// The name identifier for this agent.
pub const NAME: &'static str = "icp_ledger_agent";

/// Creates and initializes a new ICPLedgerAgent instance.
///
/// # Arguments
/// * `ctx` - The canister caller context for making ICP ledger calls.
/// * `ledgers` - A list of ledger canister IDs to interact with.
///
/// # Returns
/// A new ICPLedgerAgent instance or an error if initialization fails.
pub async fn load(ctx: &impl CanisterCaller, ledgers: &[&str]) -> Result<Self, BoxError> {
let ledgers: BTreeSet<Principal> = ledgers
.iter()
Expand All @@ -30,6 +42,11 @@ impl ICPLedgerAgent {
})
}

/// Returns the set of tools available through this agent.
///
/// # Returns
/// A ToolSet containing the balance check and transfer tools
/// or an error if tool initialization fails.
pub fn tools(&self) -> Result<ToolSet<BaseCtx>, BoxError> {
let mut tools = ToolSet::new();
tools.add(BalanceOfTool::new(self.ledgers.clone()))?;
Expand All @@ -38,19 +55,32 @@ impl ICPLedgerAgent {
}
}

/// Implementation of the [`Agent`] trait for ICPLedgerAgent.
impl Agent<AgentCtx> for ICPLedgerAgent {
/// Returns the agent's name identifier
fn name(&self) -> String {
Self::NAME.to_string()
}

/// Returns a description of the agent's purpose and capabilities.
fn description(&self) -> String {
"Interacts with ICP blockchain ledgers".to_string()
}

/// Returns a list of tool names that this agent depends on
fn tool_dependencies(&self) -> Vec<String> {
self.tools.iter().map(|v| v.to_string()).collect()
}

/// Main execution method for the agent.
///
/// # Arguments
/// * `ctx` - The agent context containing execution environment.
/// * `prompt` - The user's input prompt.
/// * `_attachment` - Optional binary attachment (not used).
///
/// # Returns
/// AgentOutput containing the response or an error if execution fails.
async fn run(
&self,
ctx: AgentCtx,
Expand Down
48 changes: 42 additions & 6 deletions examples/icp_ledger_agent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,65 @@ struct Cli {
openai_api_key: String,
}

// cargo run -p icp_ledger_agent
/// Main entry point for the ICP Ledger Agent service.
///
/// This service provides an AI-powered agent that interacts with the Internet Computer (ICP)
/// ledger and other token ledgers. It exposes a web interface for interacting with the agent and
/// managing blockchain operations.
///
/// # Configuration
/// The service can be configured via command line arguments or environment variables:
/// - Port: The port to listen on (default: 8042)
/// - ICP API host: The ICP network endpoint (default: https://icp-api.io)
/// - ID Secret: 32-byte hex-encoded secret for identity management
/// - Root Secret: 48-byte hex-encoded root secret for cryptographic operations
/// - AI Model: Supports both Deepseek and OpenAI models (Deepseek is default)
///
/// # Features
/// - Real-time interaction with ICP ledger
/// - Support for multiple token ledgers
/// - REST API interface for external integration
///
/// # Example Usage
/// ```bash
/// cargo run -p icp_ledger_agent -- \
/// --id-secret <32-byte-hex> \
/// --root-secret <48-byte-hex> \
/// --deepseek-api-key <key>
/// ```
///
/// or with environment variables in a `.env` file:
/// ```bash
/// cargo run -p icp_ledger_agent
/// ```
#[tokio::main]
async fn main() -> Result<(), BoxError> {
dotenv::dotenv().ok();
let cli = Cli::parse();

// Initialize structured logging with JSON format
Builder::with_level(&get_env_level().to_string())
.with_target_writer("*", new_writer(tokio::io::stdout()))
.init();

// Create global cancellation token for graceful shutdown
let global_cancel_token = CancellationToken::new();

// Parse and validate cryptographic secrets
let id_secret = const_hex::decode(&cli.id_secret)?;
let id_secret: [u8; 32] = id_secret.try_into().map_err(|_| "invalid id_secret")?;
let root_secret = const_hex::decode(&cli.root_secret)?;
let root_secret: [u8; 48] = root_secret.try_into().map_err(|_| "invalid root_secret")?;

// Initialize Web3 client for ICP network interaction
let web3 = Web3Client::new(&cli.ic_host, id_secret, root_secret, None, Some(true)).await?;
let my_principal = web3.get_principal();
log::info!(
"start local service, principal: {:?}",
my_principal.to_text()
);

// LL Models
// Configure AI model (Deepseek as default, fallback to OpenAI)
let model = Model::with_completer(if cli.openai_api_key.is_empty() {
Arc::new(
deepseek::Client::new(&cli.deepseek_api_key, Some(cli.deepseek_endpoint))
Expand All @@ -88,16 +122,17 @@ async fn main() -> Result<(), BoxError> {
Arc::new(openai::Client::new(&cli.openai_api_key, None).completion_model(openai::O1_MINI))
});

// ObjectStore
// Initialize in-memory object store.
// For production use, consider using a local file system store or ic_obejct_store_canister:
// let object_store = Arc::new(LocalFileSystem::new_with_prefix(store_path)?);
let object_store = Arc::new(InMemory::new());

// agent and tools
// $ICP, $PANDA
// Configure supported token ledgers (ICP and PANDA)
let token_ledgers: Vec<&str> =
vec!["ryjl3-tyaaa-aaaaa-aaaba-cai", "druyg-tyaaa-aaaaq-aactq-cai"];
let agent = ICPLedgerAgent::load(&web3, &token_ledgers).await?;

// agent engine
// Build agent engine with all configured components
let engine = EngineBuilder::new()
.with_id(my_principal)
.with_name(APP_NAME.to_string())
Expand All @@ -108,6 +143,7 @@ async fn main() -> Result<(), BoxError> {
.register_tools(agent.tools()?)?
.register_agent(agent)?;

// Initialize and start the server
let engine = engine.build(ICPLedgerAgent::NAME.to_string())?;
let mut engines = BTreeMap::new();
engines.insert(engine.id(), engine);
Expand Down

0 comments on commit 0a18867

Please sign in to comment.