gitdataai/libs/agent/chat/agent_profile.rs

208 lines
7.8 KiB
Rust

use crate::chat::{AgentExecutionProfile, AgentRole};
/// Tools available to every agent role (shared baseline).
fn shared_tools() -> Vec<String> {
vec![
// Conversation management
"chat_generate_title".into(),
// File parsing / search
"git_grep".into(),
"read_csv".into(),
"read_json".into(),
"read_sql".into(),
"read_markdown".into(),
// File content retrieval
"git_file_content".into(),
"git_blob_get".into(),
"git_blob_content".into(),
]
}
/// Researcher-specific tools (search & discovery).
fn researcher_tools() -> Vec<String> {
vec![
// Search
"git_search_commits".into(),
"repo_search".into(),
"repo_doc_search".into(),
"project_arxiv_search".into(),
"project_curl".into(),
// Index / overview
"repo_overview".into(),
"repo_readme".into(),
"repo_file_tree".into(),
"repo_doc_index".into(),
"repo_doc_read".into(),
// Lists
"project_list_repos".into(),
"project_list_members".into(),
"project_list_issues".into(),
"project_list_labels".into(),
"project_list_boards".into(),
// Log / history
"git_log".into(),
"git_reflog".into(),
"git_graph".into(),
"git_commit_info".into(),
"repo_commit_log".into(),
]
}
/// Analyst-specific tools (deep analysis & explanation).
fn analyst_tools() -> Vec<String> {
vec![
// Deep inspection
"git_show".into(),
"git_diff".into(),
"git_diff_stats".into(),
"git_blame".into(),
// Structural analysis
"repo_languages".into(),
"repo_dependencies".into(),
"repo_diff_summary".into(),
"repo_contributors".into(),
// Branch comparison
"git_branch_list".into(),
"git_branch_info".into(),
"git_branch_diff".into(),
// Project data
"project_list_issues".into(),
"project_list_repos".into(),
]
}
/// Reviewer-specific tools (evaluation & risk detection).
fn reviewer_tools() -> Vec<String> {
vec![
// Change inspection
"git_diff".into(),
"git_diff_stats".into(),
"git_blame".into(),
// Merge status
"git_branches_merged".into(),
"git_branch_info".into(),
// Tracking
"project_list_issues".into(),
"project_update_issue".into(),
// Boards
"project_list_boards".into(),
"project_update_board_card".into(),
]
}
/// Supervisor-specific tools (delegation & synthesis).
fn supervisor_tools() -> Vec<String> {
vec![
// Delegation
"call_sub_agent".into(),
]
}
/// Returns the complete tool set for a given agent role (shared + role-specific).
pub fn tools_for_role(role: &AgentRole) -> Vec<String> {
let mut tools = shared_tools();
match role {
AgentRole::Researcher => tools.extend(researcher_tools()),
AgentRole::Analyst => tools.extend(analyst_tools()),
AgentRole::Reviewer => tools.extend(reviewer_tools()),
AgentRole::Supervisor => tools.extend(supervisor_tools()),
AgentRole::Default => {} // Default role gets only shared tools
}
tools
}
pub fn supervisor_profile() -> AgentExecutionProfile {
AgentExecutionProfile {
role: AgentRole::Supervisor,
system_prompt: Some(
"You are the supervisor agent. You coordinate specialist sub-agents to produce the best answer for the user.\n\
\n\
## Delegation Strategy\n\
- Use the `call_sub_agent` tool to delegate tasks to specialist agents.\n\
- Available roles:\n\
- **researcher**: Gathers concrete facts, evidence, and data from tools and context. Best for finding information, searching code, and discovering evidence.\n\
- **analyst**: Builds coherent explanations, highlights causal links, edge cases, and tradeoffs. Best for explaining findings and reasoning about implications.\n\
- **reviewer**: Stress-tests proposals, identifies contradictions, missing assumptions, regressions, and risks. Best for quality checks and risk assessment.\n\
- Provide a clear, focused task description for each sub-agent.\n\
- You may call multiple sub-agents in sequence (call one, review its output, then decide to call another).\n\
- You may also call the same role twice with different tasks if needed.\n\
\n\
## Decision Guide\n\
- Simple factual questions: call researcher only.\n\
- Questions requiring explanation: call researcher then analyst.\n\
- Design/architecture reviews: call researcher, analyst, then reviewer.\n\
- If a sub-agent's output is insufficient, call another sub-agent for clarification.\n\
\n\
## Output Rules\n\
- After gathering all sub-agent outputs, synthesize them into one final answer.\n\
- Resolve conflicts between sub-agent outputs — prefer evidence over speculation.\n\
- Call out any remaining uncertainty explicitly.\n\
- Do not assume facts not present in sub-agent outputs.".to_string(),
),
temperature: Some(0.2),
max_tokens: Some(4000),
top_p: Some(1.0),
frequency_penalty: Some(0.0),
presence_penalty: Some(0.0),
max_tool_depth: Some(8),
allowed_tools: Some(tools_for_role(&AgentRole::Supervisor)),
disable_orchestration: true,
}
}
pub fn researcher_profile() -> AgentExecutionProfile {
AgentExecutionProfile {
role: AgentRole::Researcher,
system_prompt: Some(
"You are the researcher agent. Your job is to gather concrete facts from available tools and context. Prefer direct evidence over inference. Return structured findings, relevant code or data references, and unresolved gaps.".to_string(),
),
temperature: Some(0.1),
max_tokens: Some(1800),
top_p: Some(1.0),
frequency_penalty: Some(0.0),
presence_penalty: Some(0.0),
max_tool_depth: Some(6),
allowed_tools: Some(tools_for_role(&AgentRole::Researcher)),
disable_orchestration: true,
}
}
pub fn analyst_profile() -> AgentExecutionProfile {
AgentExecutionProfile {
role: AgentRole::Analyst,
system_prompt: Some(
"You are the analyst agent. Build a coherent explanation from the available evidence. Highlight causal links, edge cases, and tradeoffs. If evidence is weak, say so explicitly.".to_string(),
),
temperature: Some(0.2),
max_tokens: Some(1800),
top_p: Some(1.0),
frequency_penalty: Some(0.0),
presence_penalty: Some(0.0),
max_tool_depth: Some(4),
allowed_tools: Some(tools_for_role(&AgentRole::Analyst)),
disable_orchestration: true,
}
}
pub fn reviewer_profile() -> AgentExecutionProfile {
AgentExecutionProfile {
role: AgentRole::Reviewer,
system_prompt: Some(
"You are the reviewer agent. Stress-test the proposed answer. Look for contradictions, missing assumptions, regressions, and risks. Output only high-signal critiques and corrections.".to_string(),
),
temperature: Some(0.1),
max_tokens: Some(1600),
top_p: Some(1.0),
frequency_penalty: Some(0.0),
presence_penalty: Some(0.0),
max_tool_depth: Some(4),
allowed_tools: Some(tools_for_role(&AgentRole::Reviewer)),
disable_orchestration: true,
}
}
/// Whether to enable multi-agent delegation for this request.
/// Simplified from keyword-based gating: delegation is enabled when tools are available.
pub fn should_enable_delegation(_input: &str, tools_available: bool) -> bool {
tools_available
}