Skip to content
Open
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
6 changes: 6 additions & 0 deletions apps/miroflow-agent/src/core/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,5 +1198,11 @@ async def run_main_agent(
"Main Agent | Task Completed",
f"Main agent task {task_id} completed successfully",
)

# Close all persistent MCP sessions to release subprocess resources
await self.main_agent_tool_manager.close_all_sessions()
for tm in self.sub_agent_tool_managers.values():
await tm.close_all_sessions()

gc.collect()
return final_summary, final_boxed_answer, failure_experience_summary
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@
# Initialize FastMCP server
mcp = FastMCP("search_and_scrape_webpage")

# Module-level shared httpx client for connection pooling
_serper_client: httpx.AsyncClient | None = None


def _get_serper_client() -> httpx.AsyncClient:
"""Get or create a shared httpx.AsyncClient for Serper API requests."""
global _serper_client
if _serper_client is None or _serper_client.is_closed:
_serper_client = httpx.AsyncClient(timeout=60.0)
return _serper_client


@retry(
stop=stop_after_attempt(3),
Expand All @@ -47,15 +58,16 @@
async def make_serper_request(
payload: Dict[str, Any], headers: Dict[str, str]
) -> httpx.Response:
"""Make HTTP request to Serper API with retry logic."""
async with httpx.AsyncClient() as client:
response = await client.post(
f"{SERPER_BASE_URL}/search",
json=payload,
headers=headers,
)
response.raise_for_status()
return response
"""Make HTTP request to Serper API with retry logic.
Uses a module-level shared client for connection pooling."""
client = _get_serper_client()
response = await client.post(
f"{SERPER_BASE_URL}/search",
json=payload,
headers=headers,
)
response.raise_for_status()
return response


def _is_banned_url(url: str) -> bool:
Expand Down
Loading
Loading