MCPAgent is the enterprise-focused Logicore agent for large tool ecosystems. It extends the base Agent class with MCP server integration, named session lifecycle management, optional deferred tool loading, and session lifecycle callbacks.
Constructor
Parameters
LLM backend. Pass a string shorthand (
"ollama", "openai", "groq", "gemini", "azure") or a pre-constructed LLMProvider instance.Model name to use with the selected provider (e.g.
"qwen2:7b", "gpt-4o-mini"). Falls back to the provider default when None.API key for cloud providers. Required when
provider is "openai", "groq", "gemini", or "azure". Missing credentials will cause requests to fail.Custom base URL. Required for Azure deployments; optional for self-hosted OpenAI-compatible endpoints.
System prompt applied to every new session.
Print verbose internal logs covering MCP connection status, tool registration, deferred mode decisions, and session events.
Enable telemetry tracking via
TelemetryTracker.Enable memory / context middleware via
AgentrySimpleMem.Maximum number of tool-call iterations per
chat() call before the loop exits. Prevents runaway execution.Seconds of inactivity after which a session is considered stale. Used by
cleanup_stale_sessions(). Defaults to one hour.Path to an
mcp.json file on disk. Passed directly to MCPClientManager. Provide either this or mcp_config, not both.In-memory MCP server config dict (same schema as
mcp.json). Takes precedence over mcp_config_path when both are given.Explicitly enable deferred tool loading regardless of tool count. When
True, the model starts with only tool_search_regex and tools are loaded on demand.Auto-enable deferred mode when total tools (default + MCP) reaches this number. Prevents context bloat in large tool catalogs.
List of skill names or
Skill objects to load into the agent at startup.Root directory for workspace-based skill discovery.
chat()
init_mcp_servers() has not been called explicitly.
The user’s message to process.
Identifies the session context. Each session has isolated conversation history.
Automatically create the session if it does not exist. Set to
False to require explicit create_session() calls.Stream response tokens as they are generated rather than returning the complete response at the end.
Callback receiving each token string during streaming. Only used when
stream=True.Append a concise run summary to the response. Useful for audits and debugging.
str | None — the final assistant message, or None if the iteration limit was reached without a final response.
Session management methods
create_session()
on_session_created callback if set.
destroy_session()
True on success, False if the session was not found. Fires on_session_destroyed if set.
list_sessions()
session_id, message_count, created_at, last_activity, and metadata.
cleanup_stale_sessions()
last_activity exceeds session_timeout. Returns the number of sessions removed.
set_session_callbacks()
session_id string.
Tool management methods
init_mcp_servers()
mcp_config_path / mcp_config, discover their tools, and decide whether deferred mode should activate. Idempotent — safe to call multiple times.
register_tool_deferred()
preload=True the tool is also added to _loaded_tools so it is available immediately without a search step.
preload_tools()
tool_search_regex call. Useful for high-frequency tools.
get_registry_stats()
Examples
Inheritance from Agent
MCPAgent inherits the following capabilities from the base Agent class without modification:
- Internal tool execution (local Python functions)
register_tool_from_function()— overridden to also populate the deferred registry when deferred mode is active- Memory and telemetry middleware
- Provider abstraction (
LLMProvider) get_session()/AgentSessionbase session model