The Hermes Agent framework provides advanced capabilities for programmatic tool interaction and external tool discovery. This is achieved through two primary mechanisms: the Code Execution Sandbox for programmatic tool calling (PTC) and the Model Context Protocol (MCP) for integrating external tool servers.
The code execution sandbox enables the LLM to write Python scripts that call Hermes tools programmatically via RPC, collapsing multi-step tool chains into a single inference turn. This reduces context window usage by preventing intermediate tool results from entering the conversation history. tools/code_execution_tool.py3-7
The execute_code tool allows the LLM to generate a Python script that calls whitelisted tools through an RPC bridge. Only the script's stdout is returned to the LLM—intermediate tool results never enter the context window. The system supports two transports: Local (UDS/TCP) and Remote (File-based) for environments like Docker or SSH. tools/code_execution_tool.py8-29
Programmatic Tool Calling (PTC) Flow
Sources: tools/code_execution_tool.py8-29 tools/code_execution_tool.py10-25
The generate_hermes_tools_module function builds the source code for a hermes_tools.py module. This module contains stubs that map Python function calls to JSON-RPC requests. tools/code_execution_tool.py43-49
The sandbox supports a specific subset of tools defined in SANDBOX_ALLOWED_TOOLS:
web_search, web_extractread_file, write_file, search_files, patchterminalSources: tools/code_execution_tool.py61-70 tests/tools/test_code_execution.py84-118
The sandbox enforces several security boundaries and resource constraints:
DEFAULT_TIMEOUT). tools/code_execution_tool.py73DEFAULT_MAX_TOOL_CALLS). tools/code_execution_tool.py74MAX_STDOUT_BYTES) and Stderr at 10 KB (MAX_STDERR_BYTES). tools/code_execution_tool.py75-76_scrub_child_env function removes sensitive variables (keys, tokens, passwords) using _SECRET_SUBSTRINGS and _SAFE_ENV_PREFIXES while preserving operational variables in _HERMES_CHILD_ALLOWED and OS-essential variables like SYSTEMROOT on Windows. tools/code_execution_tool.py133-143 tools/code_execution_tool.py145-158 tools/code_execution_tool.py164-169 tools/code_execution_tool.py177-183Sources: tools/code_execution_tool.py51-54 tools/code_execution_tool.py72-76 tools/code_execution_tool.py145-183
Hermes Agent supports the Model Context Protocol (MCP), allowing it to connect to external tool servers (e.g., GitHub, Filesystem) and register their capabilities dynamically. tools/mcp_tool.py3-11 Configuration for MCP servers is read from ~/.hermes/config.yaml under the mcp_servers key. tools/mcp_tool.py15-52
The MCP implementation uses a dedicated background event loop (_mcp_loop) running in a daemon thread. Each server is represented by an MCPServerTask. tools/mcp_tool.py76-79 Stderr from MCP subprocesses is redirected to a shared log file ~/.hermes/logs/mcp-stderr.log to prevent TUI corruption. tools/mcp_tool.py135-140
MCP Client Integration System
Sources: tools/mcp_tool.py75-84 tools/mcp_tool.py135-156
Tools discovered from MCP servers are converted into the agent's internal tool schema. tools/mcp_tool.py5-7
configured, connecting, failed, and disabled states. tests/tools/test_mcp_tool.py126-150Sources: tools/mcp_tool.py5-7 tests/tools/test_mcp_tool.py126-173
For servers requiring browser-based authentication, mcp_oauth.py implements OAuth 2.1 with PKCE. tools/mcp_oauth.py3-7
~/.hermes/mcp-tokens/. tools/mcp_oauth.py134-1450o600 permissions. tests/tools/test_mcp_oauth.py65-88HTTPServer on localhost to capture authorization codes. tools/mcp_oauth.py16-17 tools/mcp_oauth.py51OAuthNonInteractiveError is raised if interaction is required but the environment is non-interactive. tools/mcp_oauth.py88-89Sources: tools/mcp_oauth.py3-17 tools/mcp_oauth.py134-145 tests/tools/test_mcp_oauth.py65-88 tools/mcp_oauth.py88-89
supports_parallel_tool_calls flag to allow concurrent execution of tools from the same server. tools/mcp_tool.py72-73Sources: tools/mcp_tool.py62-74
The ProcessRegistry manages background processes spawned through terminal tools, providing buffering and lifecycle tracking. tools/process_registry.py2-10
The ProcessRegistry singleton tracks ProcessSession objects, which contain metadata such as PID, command, and output buffers. tools/process_registry.py91-140
MAX_OUTPUT_CHARS) for process output. tools/process_registry.py58processes.json for recovery after gateway restarts. tools/process_registry.py55WATCH_MIN_INTERVAL_SECONDS to prevent flooding the user with notifications from background tasks. tools/process_registry.py69Sources: tools/process_registry.py2-10 tools/process_registry.py55-61 tools/process_registry.py91-140
Local execution environments use a strict blocklist to prevent sensitive Hermes environment variables from leaking into spawned subprocesses. tools/environments/local.py139-151
_SECRET_SUBSTRINGS are explicitly blocked. tools/code_execution_tool.py148-158SYSTEMROOT and COMSPEC are preserved in the sandbox to ensure basic system functionality. tools/code_execution_tool.py177-183cwd if the configured directory is deleted or inaccessible. tools/environments/local.py154-172Sources: tools/environments/local.py139-172 tools/code_execution_tool.py145-183
Refresh this wiki
This wiki was recently refreshed. Please wait 3 days to refresh again.