Skip to content

Commit 6c59863

Browse files
committed
wip(autoagents): transition to manual tool registration with AgentDeriveT
Progress on fixing compilation errors discovered during build: Changes: - agent_builder.rs: Create CodeGraphReActAgent implementing AgentDeriveT - Manual tool registration via tools() method - Use shared_tools_to_boxes() for Arc<dyn ToolT> conversion - Pass agent to ReActAgent::new() instead of using with_tools() - agent_builder.rs: Update AgentHandle type to DirectAgentHandle<ReActAgent<CodeGraphReActAgent>> - graph_tools.rs: Fix ToolCallError usage (RuntimeError not ExecutionFailed) - executor.rs: Update run_agent to use DirectAgentHandle structure Remaining issues to fix: - CodeGraphChatAdapter needs autoagents::llm::LLMProvider not ChatProvider - No system_prompt() method on AgentBuilder (need alternative) - Error::Generic doesn't exist (use correct variant) - CodeGraphAgentOutput::structured_output_format() missing This is WIP - compilation still failing, continuing investigation.
1 parent 9d59dbc commit 6c59863

File tree

3 files changed

+55
-22
lines changed

3 files changed

+55
-22
lines changed

crates/codegraph-mcp/src/autoagents/agent_builder.rs

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ impl ChatResponse for CodeGraphChatResponse {
174174
// Agent Builder
175175
// ============================================================================
176176

177-
use crate::autoagents::codegraph_agent::CodeGraphAgentOutput;
178177
use crate::autoagents::tier_plugin::TierAwarePromptPlugin;
179178
use crate::autoagents::tools::tool_executor_adapter::GraphToolFactory;
180179
use crate::autoagents::tools::graph_tools::*;
@@ -184,8 +183,39 @@ use crate::context_aware_limits::ContextTier;
184183
use autoagents::core::agent::AgentBuilder;
185184
use autoagents::core::agent::prebuilt::executor::ReActAgent;
186185
use autoagents::core::agent::memory::SlidingWindowMemory;
186+
use autoagents::core::agent::{AgentDeriveT, AgentHooks, DirectAgentHandle};
187187
use autoagents::core::error::Error as AutoAgentsError;
188-
use autoagents::core::tool::ToolT;
188+
use autoagents::core::tool::{shared_tools_to_boxes, ToolT};
189+
use autoagents_derive::AgentHooks;
190+
use crate::autoagents::codegraph_agent::CodeGraphAgentOutput;
191+
192+
/// Agent implementation for CodeGraph with manual tool registration
193+
#[derive(Debug)]
194+
pub struct CodeGraphReActAgent {
195+
tools: Vec<Arc<dyn ToolT>>,
196+
}
197+
198+
impl AgentDeriveT for CodeGraphReActAgent {
199+
type Output = CodeGraphAgentOutput;
200+
201+
fn description(&self) -> &'static str {
202+
"CodeGraph agent for analyzing code dependencies and architecture"
203+
}
204+
205+
fn name(&self) -> &'static str {
206+
"codegraph_agent"
207+
}
208+
209+
fn output_schema(&self) -> Option<serde_json::Value> {
210+
Some(CodeGraphAgentOutput::structured_output_format())
211+
}
212+
213+
fn tools(&self) -> Vec<Box<dyn ToolT>> {
214+
shared_tools_to_boxes(&self.tools)
215+
}
216+
}
217+
218+
impl AgentHooks for CodeGraphReActAgent {}
189219

190220
/// Builder for CodeGraph AutoAgents workflows
191221
pub struct CodeGraphAgentBuilder {
@@ -224,18 +254,21 @@ impl CodeGraphAgentBuilder {
224254
// Get executor adapter for tool construction
225255
let executor_adapter = self.tool_factory.adapter();
226256

227-
// Manually construct all 6 tools with the executor
228-
let tools: Vec<Box<dyn ToolT>> = vec![
229-
Box::new(GetTransitiveDependencies::new(executor_adapter.clone())),
230-
Box::new(GetReverseDependencies::new(executor_adapter.clone())),
231-
Box::new(TraceCallChain::new(executor_adapter.clone())),
232-
Box::new(DetectCycles::new(executor_adapter.clone())),
233-
Box::new(CalculateCoupling::new(executor_adapter.clone())),
234-
Box::new(GetHubNodes::new(executor_adapter.clone())),
257+
// Manually construct all 6 tools with the executor (Arc-wrapped for sharing)
258+
let tools: Vec<Arc<dyn ToolT>> = vec![
259+
Arc::new(GetTransitiveDependencies::new(executor_adapter.clone())),
260+
Arc::new(GetReverseDependencies::new(executor_adapter.clone())),
261+
Arc::new(TraceCallChain::new(executor_adapter.clone())),
262+
Arc::new(DetectCycles::new(executor_adapter.clone())),
263+
Arc::new(CalculateCoupling::new(executor_adapter.clone())),
264+
Arc::new(GetHubNodes::new(executor_adapter.clone())),
235265
];
236266

237-
// Build ReAct agent with manually constructed tools
238-
let react_agent = ReActAgent::with_tools(tools);
267+
// Create CodeGraph agent with tools
268+
let codegraph_agent = CodeGraphReActAgent { tools };
269+
270+
// Build ReAct agent with our CodeGraph agent
271+
let react_agent = ReActAgent::new(codegraph_agent);
239272

240273
// Build full agent with configuration
241274
let agent = AgentBuilder::new(react_agent)
@@ -256,7 +289,7 @@ impl CodeGraphAgentBuilder {
256289

257290
/// Handle for executing CodeGraph agent
258291
pub struct AgentHandle {
259-
pub agent: Box<dyn autoagents::core::agent::Agent>,
292+
pub agent: DirectAgentHandle<ReActAgent<CodeGraphReActAgent>>,
260293
pub tier: ContextTier,
261294
pub analysis_type: AnalysisType,
262295
}

crates/codegraph-mcp/src/autoagents/executor.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,14 @@ impl CodeGraphExecutor {
103103
/// Execute agent and convert output
104104
async fn run_agent(
105105
&self,
106-
mut agent_handle: AgentHandle,
106+
agent_handle: AgentHandle,
107107
query: String,
108108
) -> Result<CodeGraphAgentOutput, ExecutorError> {
109-
use autoagents::core::agent::Agent;
109+
use autoagents::core::agent::AgentExecutor;
110110

111111
// Execute the agent with the query
112112
let react_output = agent_handle
113+
.agent
113114
.agent
114115
.run(&query)
115116
.await

crates/codegraph-mcp/src/autoagents/tools/graph_tools.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use autoagents::core::tool::{ToolCallError, ToolInputT, ToolRuntime, ToolT};
55
use autoagents_derive::{tool, ToolInput};
66
use serde::{Deserialize, Serialize};
7-
use serde_json::Value;
87
use std::sync::Arc;
98
use crate::autoagents::tools::tool_executor_adapter::GraphToolExecutorAdapter;
109

@@ -59,7 +58,7 @@ impl ToolRuntime for GetTransitiveDependencies {
5958
"edge_type": typed_args.edge_type,
6059
"depth": typed_args.depth
6160
})
62-
).map_err(|e| ToolCallError::ExecutionFailed(e))?;
61+
).map_err(|e| ToolCallError::RuntimeError(Box::new(std::io::Error::new(std::io::ErrorKind::Other, e))))?;
6362

6463
Ok(result)
6564
}
@@ -106,7 +105,7 @@ impl ToolRuntime for GetReverseDependencies {
106105
"edge_type": typed_args.edge_type,
107106
"depth": typed_args.depth
108107
})
109-
).map_err(|e| ToolCallError::ExecutionFailed(e))?;
108+
).map_err(|e| ToolCallError::RuntimeError(Box::new(std::io::Error::new(std::io::ErrorKind::Other, e))))?;
110109

111110
Ok(result)
112111
}
@@ -153,7 +152,7 @@ impl ToolRuntime for TraceCallChain {
153152
"start_node_id": typed_args.start_node_id,
154153
"max_depth": typed_args.max_depth
155154
})
156-
).map_err(|e| ToolCallError::ExecutionFailed(e))?;
155+
).map_err(|e| ToolCallError::RuntimeError(Box::new(std::io::Error::new(std::io::ErrorKind::Other, e))))?;
157156

158157
Ok(result)
159158
}
@@ -201,7 +200,7 @@ impl ToolRuntime for DetectCycles {
201200
"edge_type": typed_args.edge_type,
202201
"max_cycle_length": typed_args.max_cycle_length
203202
})
204-
).map_err(|e| ToolCallError::ExecutionFailed(e))?;
203+
).map_err(|e| ToolCallError::RuntimeError(Box::new(std::io::Error::new(std::io::ErrorKind::Other, e))))?;
205204

206205
Ok(result)
207206
}
@@ -244,7 +243,7 @@ impl ToolRuntime for CalculateCoupling {
244243
"node_id": typed_args.node_id,
245244
"edge_type": typed_args.edge_type
246245
})
247-
).map_err(|e| ToolCallError::ExecutionFailed(e))?;
246+
).map_err(|e| ToolCallError::RuntimeError(Box::new(std::io::Error::new(std::io::ErrorKind::Other, e))))?;
248247

249248
Ok(result)
250249
}
@@ -300,7 +299,7 @@ impl ToolRuntime for GetHubNodes {
300299
"min_connections": typed_args.min_connections,
301300
"limit": typed_args.limit
302301
})
303-
).map_err(|e| ToolCallError::ExecutionFailed(e))?;
302+
).map_err(|e| ToolCallError::RuntimeError(Box::new(std::io::Error::new(std::io::ErrorKind::Other, e))))?;
304303

305304
Ok(result)
306305
}

0 commit comments

Comments
 (0)