feat: split xagent/core/agent.py into focused collaborative modules#4
Draft
Copilot wants to merge 3 commits into
Draft
feat: split xagent/core/agent.py into focused collaborative modules#4Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
- Create xagent/core/model_caller.py: ReplyType enum + ModelCaller class (OpenAI API calls with retry, streaming helpers, static message utilities) - Create xagent/core/tool_executor.py: ToolExecutor class (tool registration, invalidation-aware spec cache, semaphore-controlled concurrent execution) + make_http_agent_tool() factory function - Create xagent/core/mcp_manager.py: MCPManager class (TTL-cached MCP server tool discovery with tenacity retry) - Create xagent/core/image_processor.py: ImageProcessor class (vision-model captioning with prompt-based fallback) - Refactor xagent/core/agent.py to use the four new components; reduce from 1128 lines to ~570 lines by delegating all sub-concerns to components - Make agent.py storage imports lazy (TYPE_CHECKING guard + deferred Local imports) so importing the module no longer triggers chromadb/langfuse - Replace eager imports in xagent/core/__init__.py with lazy __getattr__ pattern matching the top-level xagent/__init__.py - Add tests/test_modular_core.py: 32 unit tests covering each new module and backward-compat proxies on Agent Co-authored-by: ZJCODE <5073837+ZJCODE@users.noreply.github.com>
…ew helper Co-authored-by: ZJCODE <5073837+ZJCODE@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor agent into focused collaborative modules
feat: split xagent/core/agent.py into focused collaborative modules
Mar 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
xagent/core/agent.pywas a 1,128-line monolith mixing OpenAI API calls, tool execution, MCP server management, image captioning, and conversation orchestration.New modules
xagent/core/model_caller.pyReplyTypeenum +ModelCaller— OpenAI API calls, retry, streaming event classification/extraction, input sanitizationxagent/core/tool_executor.pyToolExecutor— tool registration, invalidation-aware spec cache, semaphore-controlled concurrent execution;make_http_agent_tool()HTTP sub-agent factoryxagent/core/mcp_manager.pyMCPManager— MCP server connections, TTL-based caching, tool discovery with tenacity retryxagent/core/image_processor.pyImageProcessor— vision-model caption generation with prompt-based fallbackagent.py(refactored)All four components are composed inside
Agent.__init__:Additional changes
agent.py:MemoryStorageLocal/MessageStorageLocalare deferred to__init__body so importing the module no longer eagerly loads chromadb/langfuse. This incidentally fixed several pre-existing test failures (11 → 49 passing in the existing suite).xagent/core/__init__.pynow uses__getattr__-based lazy loading (matching the top-level package pattern) and exports all new public classes.tests/test_modular_core.py: 32 new unit tests covering each module's public API, static helpers, cache-invalidation logic, TTL behaviour, captioning fallback, andAgentbackward-compat proxies.Backward compatibility
All existing
Agentattributes (tools,mcp_tools,cached_tool_specs,mcp_servers) are preserved as property proxies to the internal components._register_tools()delegates toToolExecutor.register()so callers likeSwarmcontinue to work unchanged.Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.