Skip to content

Commit

Permalink
massive cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrostr committed Feb 6, 2025
1 parent d33fde2 commit bc815f7
Show file tree
Hide file tree
Showing 17 changed files with 108 additions and 206 deletions.
5 changes: 2 additions & 3 deletions listen-kit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ description = "Blockchain actions for AI agents"
documentation = "https://docs.listen-rs.com"

[features]
default = ["full"]
default = ["http"]
full = ["http", "solana", "evm"]
http = [
"solana",
"actix-web",
"actix-cors",
"actix-web-lab",
"futures-util",
"tokio-stream",
"jsonwebtoken",
"redis",
Expand Down Expand Up @@ -56,6 +55,7 @@ futures = "0.3.31"
serde_with = "3.12.0"
async-trait = "0.1.85"
ctor = "0.2.0"
futures-util = { version = "0.3" }

# evm
alloy = { version = "0.9", features = ["full"], optional = true }
Expand All @@ -77,7 +77,6 @@ spl-associated-token-account = { version = "6.0.0", optional = true }
actix-web = { version = "4", optional = true }
actix-cors = { version = "0.6", optional = true }
actix-web-lab = { version = "0.20", optional = true }
futures-util = { version = "0.3", optional = true }
tokio-stream = { version = "0.1.17", optional = true }
jsonwebtoken = { version = "9.3.0", optional = true }
redis = { version = "0.28.2", features = ["tokio-comp"], optional = true }
8 changes: 4 additions & 4 deletions listen-kit/examples/solana_agent.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#[cfg(feature = "solana")]
use {
anyhow::Result, listen_kit::agent::create_solana_agent,
listen_kit::reasoning_loop::ReasoningLoop,
anyhow::Result, listen_kit::reasoning_loop::ReasoningLoop,
listen_kit::signer::solana::LocalSolanaSigner,
listen_kit::signer::SignerContext, listen_kit::solana::util::env,
rig::completion::Message, std::sync::Arc,
listen_kit::signer::SignerContext,
listen_kit::solana::agent::create_solana_agent,
listen_kit::solana::util::env, rig::completion::Message, std::sync::Arc,
};

#[cfg(feature = "solana")]
Expand Down
127 changes: 0 additions & 127 deletions listen-kit/src/agent.rs

This file was deleted.

22 changes: 4 additions & 18 deletions listen-kit/src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ use listen_kit::http::server::run_server;
#[cfg(feature = "http")]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
use listen_kit::agent::{
create_evm_agent, create_pump_agent, create_solana_agent,
};
use listen_kit::wallet_manager::config::PrivyConfig;
use listen_kit::wallet_manager::WalletManager;

Expand All @@ -18,32 +15,21 @@ async fn main() -> std::io::Result<()> {

// Create agents based on enabled features
#[cfg(feature = "solana")]
let solana_agent = create_solana_agent()
.await
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;

#[cfg(feature = "solana")]
let pump_fun_agent = create_pump_agent()
let solana_agent = listen_kit::solana::agent::create_solana_agent()
.await
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;

#[cfg(feature = "evm")]
let evm_agent = create_evm_agent()
let evm_agent = listen_kit::evm::agent::create_evm_agent()
.await
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;

// Run server with appropriate agents based on features
#[cfg(all(feature = "solana", feature = "evm"))]
return run_server(
solana_agent,
pump_fun_agent,
evm_agent,
wallet_manager,
)
.await;
return run_server(solana_agent, evm_agent, wallet_manager).await;

#[cfg(all(feature = "solana", not(feature = "evm")))]
return run_server(solana_agent, pump_fun_agent, wallet_manager).await;
return run_server(solana_agent, wallet_manager).await;

#[cfg(all(feature = "evm", not(feature = "solana")))]
return run_server(evm_agent, wallet_manager).await;
Expand Down
17 changes: 17 additions & 0 deletions listen-kit/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,20 @@ where
SignerContext::with_signer(signer, async { f().await }).await
})
}

use rig::agent::{Agent, AgentBuilder};
use rig::providers::anthropic::completion::CompletionModel as AnthropicCompletionModel;

pub fn claude_agent_builder() -> AgentBuilder<AnthropicCompletionModel> {
rig::providers::anthropic::Client::from_env()
.agent(rig::providers::anthropic::CLAUDE_3_5_SONNET)
}

pub async fn plain_agent() -> Result<Agent<AnthropicCompletionModel>> {
Ok(claude_agent_builder()
.preamble("be nice to the users")
.max_tokens(1024)
.build())
}

pub const PREAMBLE_COMMON: &str = "";
2 changes: 1 addition & 1 deletion listen-kit/src/cross_chain/lifi/tokens.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloy::primitives::map::HashMap;
use serde::{Deserialize, Serialize};
use serde_json::Number;
use std::collections::HashMap;

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
Expand Down
27 changes: 27 additions & 0 deletions listen-kit/src/evm/agent.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use anyhow::Result;
use rig::agent::Agent;
use rig::providers::anthropic::completion::CompletionModel as AnthropicCompletionModel;

use super::tools::{
ApproveTokenForRouterSpend, GetErc20Balance, GetEthBalance, Trade,
TransferErc20, TransferEth, VerifySwapRouterHasAllowance, WalletAddress,
};
use crate::common::{claude_agent_builder, PREAMBLE_COMMON};

pub async fn create_evm_agent() -> Result<Agent<AnthropicCompletionModel>> {
Ok(claude_agent_builder()
.preamble(&format!(
"{} {}",
"you are an ethereum trading agent", PREAMBLE_COMMON
))
.max_tokens(1024)
.tool(Trade)
.tool(TransferEth)
.tool(TransferErc20)
.tool(WalletAddress)
.tool(GetEthBalance)
.tool(GetErc20Balance)
.tool(ApproveTokenForRouterSpend)
.tool(VerifySwapRouterHasAllowance)
.build())
}
1 change: 1 addition & 0 deletions listen-kit/src/evm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod abi;
pub mod agent;
pub mod balance;
pub mod data;
pub mod price;
Expand Down
2 changes: 0 additions & 2 deletions listen-kit/src/http/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ async fn stream(
let agent = match request.chain.as_deref() {
#[cfg(feature = "solana")]
Some("solana") => state.solana_agent.clone(),
#[cfg(feature = "solana")]
Some("pump") => state.pump_fun_agent.clone(),
#[cfg(feature = "evm")]
Some("evm") => state.evm_agent.clone(),
Some(chain) => {
Expand Down
5 changes: 1 addition & 4 deletions listen-kit/src/http/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ use super::state::AppState;

pub async fn run_server(
#[cfg(feature = "solana")] solana_agent: Agent<CompletionModel>,
#[cfg(feature = "solana")] pump_fun_agent: Agent<CompletionModel>,
#[cfg(feature = "evm")] evm_agent: Agent<CompletionModel>,
wallet_manager: WalletManager,
) -> std::io::Result<()> {
let mut builder = AppState::builder().with_wallet_manager(wallet_manager);

#[cfg(feature = "solana")]
{
builder = builder
.with_solana_agent(solana_agent)
.with_pump_fun_agent(pump_fun_agent);
builder = builder.with_solana_agent(solana_agent);
}

#[cfg(feature = "evm")]
Expand Down
19 changes: 0 additions & 19 deletions listen-kit/src/http/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use std::sync::Arc;
pub struct AppState {
#[cfg(feature = "solana")]
pub(crate) solana_agent: Arc<Agent<CompletionModel>>,
#[cfg(feature = "solana")]
pub(crate) pump_fun_agent: Arc<Agent<CompletionModel>>,
#[cfg(feature = "evm")]
pub(crate) evm_agent: Arc<Agent<CompletionModel>>,
pub(crate) wallet_manager: Arc<WalletManager>,
Expand All @@ -16,8 +14,6 @@ pub struct AppState {
pub struct AppStateBuilder {
#[cfg(feature = "solana")]
solana_agent: Option<Agent<CompletionModel>>,
#[cfg(feature = "solana")]
pump_fun_agent: Option<Agent<CompletionModel>>,
#[cfg(feature = "evm")]
evm_agent: Option<Agent<CompletionModel>>,
wallet_manager: Option<WalletManager>,
Expand All @@ -34,8 +30,6 @@ impl AppStateBuilder {
Self {
#[cfg(feature = "solana")]
solana_agent: None,
#[cfg(feature = "solana")]
pump_fun_agent: None,
#[cfg(feature = "evm")]
evm_agent: None,
wallet_manager: None,
Expand All @@ -51,15 +45,6 @@ impl AppStateBuilder {
self
}

#[cfg(feature = "solana")]
pub fn with_pump_fun_agent(
mut self,
agent: Agent<CompletionModel>,
) -> Self {
self.pump_fun_agent = Some(agent);
self
}

#[cfg(feature = "evm")]
pub fn with_evm_agent(mut self, agent: Agent<CompletionModel>) -> Self {
self.evm_agent = Some(agent);
Expand All @@ -80,10 +65,6 @@ impl AppStateBuilder {
solana_agent: Arc::new(self.solana_agent.ok_or(
"Solana agent is required when solana feature is enabled",
)?),
#[cfg(feature = "solana")]
pump_fun_agent: Arc::new(self.pump_fun_agent.ok_or(
"Pump fun agent is required when solana feature is enabled",
)?),
#[cfg(feature = "evm")]
evm_agent: Arc::new(self.evm_agent.ok_or(
"EVM agent is required when evm feature is enabled",
Expand Down
6 changes: 1 addition & 5 deletions listen-kit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ pub mod evm;
#[cfg(feature = "http")]
pub mod wallet_manager;

// this might not have to be feature full, if privy is not
#[cfg(feature = "full")]
pub mod cross_chain;

pub mod agent;
pub mod common;
pub mod cross_chain;
pub mod reasoning_loop;
pub mod signer;

Expand Down
Loading

0 comments on commit bc815f7

Please sign in to comment.