mirror of
https://github.com/temporal-community/temporal-ai-agent.git
synced 2026-03-15 05:58:08 +01:00
Improve implementation of is_mcp_tool (#53)
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import inspect
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from typing import Any, Deque, Dict
|
from typing import Any, Deque, Dict
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ from temporalio.common import RetryPolicy
|
|||||||
from temporalio.exceptions import ActivityError
|
from temporalio.exceptions import ActivityError
|
||||||
|
|
||||||
from models.data_types import ConversationHistory, ToolPromptInput
|
from models.data_types import ConversationHistory, ToolPromptInput
|
||||||
from models.tool_definitions import AgentGoal
|
from models.tool_definitions import AgentGoal, ToolDefinition
|
||||||
from prompts.agent_prompt_generators import (
|
from prompts.agent_prompt_generators import (
|
||||||
generate_missing_args_prompt,
|
generate_missing_args_prompt,
|
||||||
generate_tool_completion_prompt,
|
generate_tool_completion_prompt,
|
||||||
@@ -25,60 +26,15 @@ def is_mcp_tool(tool_name: str, goal: AgentGoal) -> bool:
|
|||||||
if not goal.mcp_server_definition:
|
if not goal.mcp_server_definition:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Check if the tool name matches any MCP tools that were loaded
|
# Identify MCP tools by checking if they're not in the original static tools
|
||||||
# We can identify MCP tools by checking if they're not in the original static tools
|
import tools.tool_registry
|
||||||
from tools.tool_registry import (
|
|
||||||
book_pto_tool,
|
return not any(
|
||||||
book_trains_tool,
|
tool.name == tool_name
|
||||||
change_goal_tool,
|
for _, tool in inspect.getmembers(tools.tool_registry)
|
||||||
create_invoice_tool,
|
if isinstance(tool, ToolDefinition)
|
||||||
current_pto_tool,
|
|
||||||
ecomm_get_order,
|
|
||||||
ecomm_list_orders,
|
|
||||||
ecomm_track_package,
|
|
||||||
financial_check_account_is_valid,
|
|
||||||
financial_get_account_balances,
|
|
||||||
financial_move_money,
|
|
||||||
financial_submit_loan_approval,
|
|
||||||
find_events_tool,
|
|
||||||
food_add_to_cart_tool,
|
|
||||||
future_pto_calc_tool,
|
|
||||||
give_hint_tool,
|
|
||||||
guess_location_tool,
|
|
||||||
list_agents_tool,
|
|
||||||
paycheck_bank_integration_status_check,
|
|
||||||
search_fixtures_tool,
|
|
||||||
search_flights_tool,
|
|
||||||
search_trains_tool,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
static_tool_names = {
|
|
||||||
list_agents_tool.name,
|
|
||||||
change_goal_tool.name,
|
|
||||||
give_hint_tool.name,
|
|
||||||
guess_location_tool.name,
|
|
||||||
search_flights_tool.name,
|
|
||||||
search_trains_tool.name,
|
|
||||||
book_trains_tool.name,
|
|
||||||
create_invoice_tool.name,
|
|
||||||
search_fixtures_tool.name,
|
|
||||||
find_events_tool.name,
|
|
||||||
current_pto_tool.name,
|
|
||||||
future_pto_calc_tool.name,
|
|
||||||
book_pto_tool.name,
|
|
||||||
paycheck_bank_integration_status_check.name,
|
|
||||||
financial_check_account_is_valid.name,
|
|
||||||
financial_get_account_balances.name,
|
|
||||||
financial_move_money.name,
|
|
||||||
financial_submit_loan_approval.name,
|
|
||||||
ecomm_list_orders.name,
|
|
||||||
ecomm_get_order.name,
|
|
||||||
ecomm_track_package.name,
|
|
||||||
food_add_to_cart_tool.name,
|
|
||||||
}
|
|
||||||
|
|
||||||
return tool_name not in static_tool_names
|
|
||||||
|
|
||||||
|
|
||||||
async def handle_tool_execution(
|
async def handle_tool_execution(
|
||||||
current_tool: str,
|
current_tool: str,
|
||||||
|
|||||||
Reference in New Issue
Block a user