Thanks to visit codestin.com
Credit goes to github.com

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
23 changes: 17 additions & 6 deletions crates/forge_app/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::sync::Arc;

Expand Down Expand Up @@ -51,9 +52,6 @@ impl<S: Services> ForgeApp<S> {
.unwrap_or_default()
.expect("conversation for the request should've been created at this point.");

// Get tool definitions and models
let system_tools = self.tool_registry.list().await?;
let mcp_tools = self.services.mcp_service().list().await?;
let config = services.get_app_config().await.unwrap_or_default();
let provider = services
.get_provider(config)
Expand Down Expand Up @@ -100,6 +98,7 @@ impl<S: Services> ForgeApp<S> {
// Prepare agents with user configuration and subscriptions
let agents = services.get_agents().await?;

let mcp_tools = self.services.mcp_service().list().await?;
let agent = agents
.into_iter()
.map(|agent| {
Expand All @@ -110,9 +109,21 @@ impl<S: Services> ForgeApp<S> {
.find(|agent| agent.has_subscription(&chat.event.name))
.ok_or(crate::Error::UnsubscribedEvent(chat.event.name.to_owned()))?;

let mut tool_definitions = Vec::new();
tool_definitions.extend(system_tools);
tool_definitions.extend(mcp_tools.values().flatten().cloned());
// Get system and mcp tool definitions
let tool_definitions = self.tool_registry.list().await?;
let uniq_tool_definitions = tool_definitions
.iter()
.map(|tool| (&tool.name, tool))
.collect::<HashMap<_, _>>();

let tool_definitions = agent
.tools
.iter()
.flatten()
.flat_map(|tool| uniq_tool_definitions.get(tool))
.cloned()
.cloned()
.collect::<Vec<_>>();

// Create the orchestrator with all necessary dependencies
let orch = Orchestrator::new(
Expand Down
25 changes: 8 additions & 17 deletions crates/forge_app/src/orch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,14 @@ impl<S: AgentService> Orchestrator<S> {

/// Get the allowed tools for an agent
fn get_allowed_tools(&self) -> anyhow::Result<Vec<ToolDefinition>> {
let agent = &self.agent;
let mut tools = vec![ToolsDiscriminants::AttemptCompletion.definition()];

// Add system tools
if !self.tool_definitions.is_empty() {
let allowed = agent.tools.iter().flatten().collect::<HashSet<_>>();
if !allowed.is_empty() {
tools.extend(
self.tool_definitions
.iter()
.filter(|tool| allowed.contains(&tool.name))
.cloned(),
);
}
}

Ok(tools)
Ok(self
.tool_definitions
.iter()
.cloned()
.chain(std::iter::once(
ToolsDiscriminants::AttemptCompletion.definition(),
))
.collect::<Vec<_>>())
}

/// Checks if parallel tool calls is supported by agent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ You are Forge
</system_information>

<available_tools>
<tool>{"name":"attempt_completion","description":"After each tool use, the user will respond with the result of\n that tool use, i.e. if it succeeded or failed, along with any reasons for\n failure. Once you\\'ve received the results of tool uses and can confirm that\n the task is complete, use this tool to present the result of your work to\n the user in markdown format. The user may respond with feedback if they are\n not satisfied with the result, which you can use to make improvements and\n try again. IMPORTANT NOTE: This tool CANNOT be used until you\\'ve confirmed\n from the user that any previous tool uses were successful. Failure to do so\n will result in code corruption and system failure. Before using this tool,\n you must ask yourself if you\\'ve confirmed from the user that any previous\n tool uses were successful. If not, then DO NOT use this tool.","arguments":{"result":{"description":"The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance.","type":"string","is_required":true}}}</tool>
<tool>{"name":"fs_read","description":"","arguments":{}}</tool>
<tool>{"name":"fs_write","description":"","arguments":{}}</tool>
<tool>{"name":"attempt_completion","description":"After each tool use, the user will respond with the result of\n that tool use, i.e. if it succeeded or failed, along with any reasons for\n failure. Once you\\'ve received the results of tool uses and can confirm that\n the task is complete, use this tool to present the result of your work to\n the user in markdown format. The user may respond with feedback if they are\n not satisfied with the result, which you can use to make improvements and\n try again. IMPORTANT NOTE: This tool CANNOT be used until you\\'ve confirmed\n from the user that any previous tool uses were successful. Failure to do so\n will result in code corruption and system failure. Before using this tool,\n you must ask yourself if you\\'ve confirmed from the user that any previous\n tool uses were successful. If not, then DO NOT use this tool.","arguments":{"result":{"description":"The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance.","type":"string","is_required":true}}}</tool>
</available_tools>

<tool_usage_example>
Expand Down
Loading