This guide provides detailed information for developers who want to understand, modify, or extend the Synapticore framework.
- Architecture Overview
- Core Components
- Development Workflow
- Adding New Features
- Working with MCP Tools
- Testing Your Changes
- Common Development Tasks
- Best Practices
- Troubleshooting
The Synapticore framework follows a modular architecture designed to facilitate complex multi-agent systems with different language models and external tool integration. Here's a high-level overview:
src/
└── synapticore/
├── llms/ # LLM Registry and model management
├── mcp/ # MCP session and tool management
├── agents/ # Agent and supervisor management
├── utils/ # Utility functions
examples/ # Usage examples
tests/ # Test suite
└── synapticore/
├── llms/ # LLM Registry and model management tests
├── mcp/ # MCP session and tool management tests
├── agents/ # Agent and supervisor management test
The system uses a hierarchical approach where:
- Leaf nodes are specialized agents with specific tools and capabilities
- Intermediate nodes are supervisors that manage groups of agents
- Root nodes are top-level supervisors that coordinate the entire system
This hierarchical structure allows for complex delegations and specializations while maintaining a coherent overall system.
The LLMRegistry manages multiple language models and provides them to agents as needed:
- Key Concept: Each language model is registered with a unique ID and can be referenced by this ID
- Main File:
llms/registry.py - Extension Point: Add methods to support additional LLM providers
The MCPManager handles integration with the langchain-mcp-adapters for external tool access:
- Key Concept: Manages connections to MCP servers and provides their tools to agents
- Main File:
mcp/manager.py - Extension Point: Add support for additional connection types or tool discovery methods
The AgentManager ties everything together, managing the creation, connection, and execution of agents:
- Key Concept: Maintains a hierarchy of agents and supervisors with parent-child relationships
- Main File:
agents/manager.py - Extension Point: Add new agent types or modify hierarchy management
- Python 3.8 or higher
- UV - Fast Python package installer and resolver
git clone https://github.com/yourusername/synapticore.git
cd synapticoreUV provides faster dependency resolution and installation compared to pip:
# Install UV if you don't have it yet
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/uv/releases/download/0.5.24/uv-installer.sh | sh
# Create a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Synchronize the project dependencies with UV
uv pip sync -e ".[dev,all]"If you prefer using pip:
# Create a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install the package with all dependencies
pip install -e ".[all,dev]"This repository includes a DevContainer configuration for VSCode, which provides a fully configured development environment:
- Install VSCode and the Dev Containers extension
- Clone the repository and open it in VSCode
- When prompted, click "Reopen in Container" or use the command palette (F1) and select "Dev Containers: Reopen in Container"
- The container will automatically set up the development environment with all dependencies
- Make Changes: Modify the code in your editor of choice
- Run Tests: Execute
pytestto ensure your changes don't break existing functionality - Run Examples: Test your changes with the provided examples
- Format Code: Run
black .andisort .to ensure code style consistency - Commit Changes: Use descriptive commit messages explaining what you changed and why
-
Add a new method to
LLMRegistryfollowing this pattern:def register_new_provider( self, model_id: str, model: str = "default-model-name", **kwargs ) -> None: try: from langchain_new_provider import ChatNewProvider chat_model = ChatNewProvider(model=model, **kwargs) self.register(model_id, chat_model) except ImportError: raise ImportError( "langchain-new-provider is not installed. Please install it." )
-
Update the package dependencies in
pyproject.tomlto include the new provider as an optional dependency.
-
Create a new function in
agents/types.py(you may need to create this file):def create_custom_agent( model: LanguageModelLike, tools: List[Union[BaseTool, Callable]], name: str, prompt: Optional[Union[str, SystemMessage, Callable, Any]] = None, **kwargs ) -> Pregel: # Custom agent creation logic ... return agent
-
Add a method to
AgentManagerthat uses your new agent creation function.
-
Define your tools using the MCP protocol:
from mcp.server import ToolServerProtocol, register_tool, run @register_tool("my_custom_tool") async def my_custom_tool(param1: str, param2: int) -> Dict[str, Any]: # Tool implementation return {"result": f"Processed {param1} {param2} times"} if __name__ == "__main__": server = ToolServerProtocol() run(server)
-
Register the server with the MCP Manager:
# For stdio connection manager.mcp_manager.register_stdio_server( server_id="my_tools", command="python", args=["path/to/my_server.py"], ) # For SSE connection manager.mcp_manager.register_sse_server( server_id="web_tools", url="http://localhost:8000/sse", )
-
Initialize the MCP Manager:
await manager.mcp_manager.initialize()
-
Create an agent that uses the MCP tools:
agent_id = await manager.create_agent_with_mcp( name="mcp_agent", mcp_server_ids=["my_tools", "web_tools"], )
Run the full test suite:
pytestTest a specific module:
pytest tests/test_llm_registry.pyThe examples in the examples/ directory serve as integration tests. Run them to ensure your changes work in a complete system:
python -m synapticore.examples.complex_hierarchy- Create or modify test files in the
tests/directory - Follow the existing test patterns using the
unittestframework - Use mocks for external dependencies to ensure tests run quickly and reliably
-
Update
pyproject.tomlwith the new dependency -
For optional dependencies, add them to the appropriate section:
[project.optional-dependencies] new-feature = ["new-package>=1.0.0"] all = [ # Include existing dependencies "new-package>=1.0.0", ]
-
Update the environment with UV:
uv pip sync -e ".[all,dev]"
The visualization logic is in utils/hierarchy.py. To modify:
- Update the
generate_mermaid_diagramfunction for Mermaid diagram generation - Update the
print_hierarchy_treefunction for console output
- Follow the Black code formatting style
- Use isort for import sorting
- Add docstrings to all public functions and classes
- Use type hints consistently
- Maintain separation of concerns between modules
- Keep the hierarchy structure clean and consistent
- Make all components extendable and customizable
- Provide sensible defaults while allowing for configuration
- Write unit tests for all new functionality
- Mock external dependencies in tests
- Test edge cases and error handling
- Ensure backwards compatibility
Symptom: RuntimeError: MCPManager is not initialized.
Solution: Ensure you've called await mcp_manager.initialize() before trying to use MCP tools.
Symptom: ValueError: No LLM ID provided and no default LLM set.
Solution: Either provide an llm_id when creating the agent or set a default_llm_id when creating the AgentManager.
Symptom: ImportError: langchain-openai is not installed.
Solution: Install the optional dependency: uv pip install "synapticore[openai]" or uv pip install langchain-openai.
- Use
print_hierarchy()to visualize the current agent structure - Enable more verbose logging to see what's happening:
import logging logging.basicConfig(level=logging.DEBUG)
- Inspect message content at each step of the process to identify where issues occur
This developer guide should be considered a living document. As the framework evolves, this guide should be updated to reflect new features, patterns, and best practices.