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
3 changes: 3 additions & 0 deletions lib/galaxy/agents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .orchestrator import WorkflowOrchestratorAgent
from .registry import AgentRegistry
from .router import QueryRouterAgent
from .tools import ToolRecommendationAgent

__all__ = [
"AgentType",
Expand All @@ -25,6 +26,7 @@
"ErrorAnalysisAgent",
"CustomToolAgent",
"WorkflowOrchestratorAgent",
"ToolRecommendationAgent",
]

# Global agent registry instance
Expand All @@ -35,3 +37,4 @@
agent_registry.register(AgentType.ERROR_ANALYSIS, ErrorAnalysisAgent)
agent_registry.register(AgentType.CUSTOM_TOOL, CustomToolAgent)
agent_registry.register(AgentType.ORCHESTRATOR, WorkflowOrchestratorAgent)
agent_registry.register(AgentType.TOOL_RECOMMENDATION, ToolRecommendationAgent)
1 change: 1 addition & 0 deletions lib/galaxy/agents/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class AgentType:
ERROR_ANALYSIS = "error_analysis"
CUSTOM_TOOL = "custom_tool"
ORCHESTRATOR = "orchestrator"
TOOL_RECOMMENDATION = "tool_recommendation"


# Internal agent response model (simplified for internal use)
Expand Down
15 changes: 11 additions & 4 deletions lib/galaxy/agents/prompts/router.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ For off-topic questions (general coding, non-scientific topics, unrelated softwa
## How to Respond

**Answer directly** for:
- Galaxy platform questions ("How do I run BWA?", "What is a workflow?")
- Tool discovery ("What tools analyze RNA-seq data?")
- Usage guidance ("How do I upload files?")
- Galaxy platform questions ("What is a workflow?", "How do I upload files?")
- How to USE a specific tool ("How do I run BWA?", "What parameters does HISAT2 need?")
- Scientific analysis best practices
- Galaxy features and capabilities

**Use `hand_off_to_tool_recommendation`** when user:
- Asks what tool to use for a task ("What tool should I use to align reads?")
- Wants to find/discover tools ("Is there a tool that converts BAM to FASTQ?")
- Needs help choosing between tools for an analysis type
- Asks "what tools are available for X?"

**Use `hand_off_to_error_analysis`** when user:
- Has a failed job with error messages or exit codes
- Is asking about stderr/stdout from a tool run
Expand All @@ -43,8 +48,10 @@ For off-topic questions (general coding, non-scientific topics, unrelated softwa

## Important Distinctions

- "What tool does X?" → Answer directly (tool discovery)
- "What tool should I use for X?" → Use hand_off_to_tool_recommendation
- "Is there a tool that does X?" → Use hand_off_to_tool_recommendation
- "How do I use tool X?" → Answer directly (usage help)
- "What parameters does X need?" → Answer directly (usage help)
- "Create a tool that does X" → Use hand_off_to_custom_tool
- "My job failed" → Use hand_off_to_error_analysis

Expand Down
42 changes: 42 additions & 0 deletions lib/galaxy/agents/prompts/tool_recommendation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Galaxy Tool Recommendation Agent

You are a Galaxy Project expert specializing in tool discovery and recommendation.

Your goal is to help users find the right tools for their bioinformatics tasks by providing practical recommendations with clear reasoning.

## CRITICAL: Tool Availability

**This Galaxy server only has certain tools installed. You MUST verify tools exist before recommending them.**

1. **ALWAYS call `search_galaxy_tools` FIRST** before making any recommendations
2. **ONLY recommend tools that appear in the search results** - if a tool doesn't show up in the search, it is NOT installed on this server
3. If your search returns no results for a common tool (like BWA, HISAT2, etc.), that means it's not installed
4. When a well-known tool is not installed, tell the user: "While [tool name] would typically be recommended for this task, it doesn't appear to be installed on this Galaxy server. You may want to contact your administrator to request its installation."

## Available Tools

- **`search_galaxy_tools(query)`** - Search for tools by keyword. Always start here.
- **`get_galaxy_tool_details(tool_id)`** - Get detailed info (inputs, outputs, version) for a specific tool. Use after searching to provide better recommendations.
- **`get_galaxy_tool_categories()`** - List available tool categories. Use when user asks "what kinds of tools are available?" or to understand the server's capabilities.

## Recommendation Process

1. Understand the user's task and data types
2. **Call `search_galaxy_tools` with relevant keywords** (e.g., "alignment", "mapping", "fastq")
3. Optionally call `get_galaxy_tool_details` on promising candidates to get input/output format info
4. Recommend tools from the search results, using their exact IDs
5. If no suitable tools are found, be honest about the limitation

## Tool IDs

- Use ONLY the exact `id` field from search results
- Never guess or fabricate tool IDs based on your training knowledge
- If you know a tool exists in Galaxy generally but it's not in the search results, it's NOT available on this server

## Best Practices

- Prioritize tools that are well-maintained and widely used
- Consider the user's experience level
- Explain why you're recommending specific tools
- Mention important parameters or configuration options
- Suggest workflows when multiple tools are needed
40 changes: 40 additions & 0 deletions lib/galaxy/agents/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Answer general Galaxy questions directly (returns str)
- Hand off to error_analysis for job debugging
- Hand off to custom_tool for explicit tool creation requests
- Hand off to tool_recommendation for tool discovery
"""

import logging
Expand Down Expand Up @@ -58,13 +59,15 @@ def _create_agent(self) -> Agent[GalaxyAgentDependencies, str]:
# Create output functions for specialist handoff
error_handoff = self._create_error_analysis_handoff()
tool_handoff = self._create_custom_tool_handoff()
tool_rec_handoff = self._create_tool_recommendation_handoff()

return Agent(
self._get_model(),
deps_type=GalaxyAgentDependencies,
output_type=[
error_handoff,
tool_handoff,
tool_rec_handoff,
str, # Default: answer directly
],
system_prompt=self.get_system_prompt(),
Expand Down Expand Up @@ -166,6 +169,43 @@ async def hand_off_to_custom_tool(

return hand_off_to_custom_tool

def _create_tool_recommendation_handoff(self):
"""Create output function for tool recommendation handoff."""

async def hand_off_to_tool_recommendation(
ctx: RunContext[GalaxyAgentDependencies],
query: str,
) -> str:
"""Route to tool recommendation agent for finding Galaxy tools.

Use this when the user:
- Asks what tool to use for a task ("what tool aligns reads?")
- Wants to find tools for a specific analysis type
- Needs help discovering available tools
- Asks "is there a tool that does X?"

Do NOT use for:
- How to USE a specific tool (answer directly)
- Creating NEW tools (use hand_off_to_custom_tool)
- Job errors (use hand_off_to_error_analysis)

Args:
query: The tool discovery question
"""
from .tools import ToolRecommendationAgent

log.info(f"Router handing off to tool_recommendation: '{query[:100]}...'")

try:
agent = ToolRecommendationAgent(ctx.deps)
result = await agent.process(query)
return result.content
except Exception as e:
log.error(f"Tool recommendation handoff failed: {e}")
return f"I encountered an issue while searching for tools. Please try again or browse the tool panel directly. Error: {e}"

return hand_off_to_tool_recommendation

async def process(self, query: str, context: Optional[dict[str, Any]] = None) -> AgentResponse:
"""
Process a query and return the response.
Expand Down
Loading
Loading