Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions amico-mods/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "amico-mods"
version = "0.0.3"
version = "0.0.4"
edition = "2024"
description = "The plugins of the Amico AI Agent Framework"
repository = "https://github.com/AIMOverse/amico"
Expand All @@ -13,11 +13,10 @@ license = "MIT OR Apache-2.0"
default = ["full"]

# The standard set of plugins
std-full = ["std-providers", "std-services", "std-tasks"]
std-full = ["std-providers", "std-chat-session", "std-tasks"]
std-providers = ["std-providers-rig"]
std-providers-rig = ["rig-core"]
std-services = ["std-services-in-memory"]
std-services-in-memory = []
std-chat-session = []
std-tasks = ["std-cli-chatbot", "std-audio-chatbot"]
std-cli-chatbot = []
std-audio-chatbot = ["dep:amico-hal", "amico-hal/os-common"]
Expand Down
1 change: 1 addition & 0 deletions amico-mods/src/std/ai/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod providers;
pub mod services;
pub mod session;
5 changes: 0 additions & 5 deletions amico-mods/src/std/ai/services/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
#[cfg(feature = "std-services-in-memory")]
mod in_memory;
#[cfg(feature = "std-services-in-memory")]
pub use in_memory::*;

pub mod speech;
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,46 @@ fn debug_history(history: &[Message]) -> String {
// Convert message to a prettier shorter string
for m in history.iter() {
match m {
Message::Assistant(text) => messages.push_str(&format!("a: {}\n", text)),
Message::User(text) => messages.push_str(&format!("u: {}\n", text)),
Message::Assistant(text) => messages.push_str(&format!("- a: {}\n", text)),
Message::User(text) => messages.push_str(&format!("- u: {}\n", text)),
Message::ToolCall(name, id, params) => {
messages.push_str(&format!("tc: {}[{}] ({})\n", name, id, params))
messages.push_str(&format!("- tc: {}[{}] ({})\n", name, id, params))
}
Message::ToolResult(name, id, params) => {
messages.push_str(&format!("tr: {}[{}] => {}\n", name, id, params))
messages.push_str(&format!("- tr: {}[{}] => {}\n", name, id, params))
}
}
}

messages
}

/// The standard implementation of a chat session.
///
/// This session manages chat history in a `Vec<Message>`, and executes tool call
/// functions.
#[derive(Debug)]
pub struct InMemoryService<M: Model + Send> {
pub struct ChatSession<M: Model + Send> {
/// The context config for the service
pub ctx: SessionContext<M>,

/// In-memory Chat history storage
pub history: Vec<Message>,
}

impl<M: Model + Send> Session for InMemoryService<M> {
impl<M: Model + Send> ChatSession<M> {
/// Create a new in-memory session from an existing history of messages.
pub fn from_history(ctx: SessionContext<M>, history: Vec<Message>) -> Self {
Self { ctx, history }
}
}

impl<M: Model + Send> Session for ChatSession<M> {
type Model = M;

fn from_ctx(context: SessionContext<M>) -> Self {
fn from_ctx(ctx: SessionContext<M>) -> Self {
Self {
ctx: context,
ctx,
history: Vec::new(),
}
}
Expand Down Expand Up @@ -123,8 +134,8 @@ impl<M: Model + Send> Session for InMemoryService<M> {
}
}

impl<M: Model + Send> IntoResourceMut<InMemoryService<M>> for InMemoryService<M> {
fn into_resource_mut(self) -> ResourceMut<InMemoryService<M>> {
ResourceMut::new("InMemoryService", self)
impl<M: Model + Send> IntoResourceMut<ChatSession<M>> for ChatSession<M> {
fn into_resource_mut(self) -> ResourceMut<ChatSession<M>> {
ResourceMut::new("chat-session", self)
}
}
8 changes: 3 additions & 5 deletions amico/src/engine/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ use std::sync::mpsc::channel;
use amico::resource::Resource;
use amico::{ai::completion::SessionDyn, resource::ResourceMut};
use amico_core::{traits::System, world::HandlerRegistry};
use amico_mods::std::ai::session::ChatSession;
use amico_mods::std::ai::{
providers::rig::RigProvider,
services::{
InMemoryService,
speech::{speech_to_text, text_to_speech},
},
services::speech::{speech_to_text, text_to_speech},
};
use evenio::prelude::*;

Expand Down Expand Up @@ -173,7 +171,7 @@ impl System for SpeechSystem {
}

pub struct CompletionSystem {
pub service_resource: ResourceMut<InMemoryService<RigProvider>>,
pub service_resource: ResourceMut<ChatSession<RigProvider>>,
}

impl System for CompletionSystem {
Expand Down
12 changes: 6 additions & 6 deletions amico/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use amico::resource::{IntoResource, IntoResourceMut};
use amico_core::{Agent, OnFinish};
use amico_mods::runtime::storage::fs::FsStorage;
use amico_mods::std::ai::providers::rig::{RigProvider, providers};
use amico_mods::std::ai::services::InMemoryService;
use amico_mods::std::ai::session::ChatSession;
use amico_mods::web3::solana::balance::BalanceSensor;
use amico_mods::web3::solana::client::SolanaClient;
use amico_mods::web3::solana::trade::TradeEffector;
Expand Down Expand Up @@ -113,8 +113,8 @@ async fn main() {
&base_url,
));

// Create the Service
let service = SessionBuilder::new(provider)
// Create the global chat session
let global_session = SessionBuilder::new(provider)
.model("gpt-4o".to_string())
.system_prompt(AMICO_SYSTEM_PROMPT.to_string())
.temperature(0.2)
Expand All @@ -124,16 +124,16 @@ async fn main() {
.tool(trade_effector.get().tool())
.tool(a2a.send_message_tool())
.tool(a2a.contact_list_tool())
.build::<InMemoryService<RigProvider>>();
.build::<ChatSession<RigProvider>>();

println!();
println!("Agent wallet addresses:");
println!("{}", wallet.get().pubkey_list());

println!();
println!("Tools enabled:\n{}", service.ctx.tools.describe());
println!("Tools enabled:\n{}", global_session.ctx.tools.describe());

let service_resource = service.into_resource_mut();
let service_resource = global_session.into_resource_mut();

// Initialize ECS
let mut agent = Agent::new(DispatchStrategy);
Expand Down
Loading