Mcp enhancements (#43)

* reuses MCP connections in each worker for efficiency

* you can see your food

* you can see your food

* prompt eng around images
This commit is contained in:
Steve Androulakis
2025-06-16 08:37:32 -07:00
committed by GitHub
parent 49dd00ec3b
commit 861e55a8d0
7 changed files with 294 additions and 42 deletions

View File

@@ -12,6 +12,7 @@ from activities.tool_activities import (
mcp_list_tools,
)
from shared.config import TEMPORAL_TASK_QUEUE, get_temporal_client
from shared.mcp_client_manager import MCPClientManager
from workflows.agent_goal_workflow import AgentGoalWorkflow
@@ -23,11 +24,14 @@ async def main():
llm_model = os.environ.get("LLM_MODEL", "openai/gpt-4")
print(f"Worker will use LLM model: {llm_model}")
# Create shared MCP client manager
mcp_client_manager = MCPClientManager()
# Create the client
client = await get_temporal_client()
# Initialize the activities class
activities = ToolActivities()
# Initialize the activities class with injected manager
activities = ToolActivities(mcp_client_manager)
print(f"ToolActivities initialized with LLM model: {llm_model}")
# If using Ollama, pre-load the model to avoid cold start latency
@@ -54,25 +58,31 @@ async def main():
print("Worker ready to process tasks!")
logging.basicConfig(level=logging.INFO)
# Run the worker
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as activity_executor:
worker = Worker(
client,
task_queue=TEMPORAL_TASK_QUEUE,
workflows=[AgentGoalWorkflow],
activities=[
activities.agent_validatePrompt,
activities.agent_toolPlanner,
activities.get_wf_env_vars,
activities.mcp_tool_activity,
dynamic_tool_activity,
mcp_list_tools,
],
activity_executor=activity_executor,
)
# Run the worker with proper cleanup
try:
with concurrent.futures.ThreadPoolExecutor(
max_workers=100
) as activity_executor:
worker = Worker(
client,
task_queue=TEMPORAL_TASK_QUEUE,
workflows=[AgentGoalWorkflow],
activities=[
activities.agent_validatePrompt,
activities.agent_toolPlanner,
activities.get_wf_env_vars,
activities.mcp_tool_activity,
dynamic_tool_activity,
mcp_list_tools,
],
activity_executor=activity_executor,
)
print(f"Starting worker, connecting to task queue: {TEMPORAL_TASK_QUEUE}")
await worker.run()
print(f"Starting worker, connecting to task queue: {TEMPORAL_TASK_QUEUE}")
await worker.run()
finally:
# Cleanup MCP connections when worker shuts down
await mcp_client_manager.cleanup()
if __name__ == "__main__":