Initialize the YAML Agent. Args: mcp_url: URL of the MCP server for tool execution. tool_config_fp: Optional path to tool configuration file. session_id: Optional MCP session ID for resuming sessions. llm_config: Optional LLM configuration for
(
self,
mcp_url: Optional[str] = None,
tool_config_fp: Optional[str] = None,
*,
session_id: Optional[str] = None,
llm_config: Optional[LLMConfig] = None,
mcp_client: Optional["MCPClient"] = None,
)
| 100 | ) |
| 101 | |
| 102 | def __init__( |
| 103 | self, |
| 104 | mcp_url: Optional[str] = None, |
| 105 | tool_config_fp: Optional[str] = None, |
| 106 | *, |
| 107 | session_id: Optional[str] = None, |
| 108 | llm_config: Optional[LLMConfig] = None, |
| 109 | mcp_client: Optional["MCPClient"] = None, |
| 110 | ) -> None: |
| 111 | """Initialize the YAML Agent. |
| 112 | |
| 113 | Args: |
| 114 | mcp_url: URL of the MCP server for tool execution. |
| 115 | tool_config_fp: Optional path to tool configuration file. |
| 116 | session_id: Optional MCP session ID for resuming sessions. |
| 117 | llm_config: Optional LLM configuration for custom providers/endpoints. |
| 118 | mcp_client: Optional pre-configured MCPClient instance. If provided, |
| 119 | uses this instead of creating a new MCPClient from mcp_url. |
| 120 | """ |
| 121 | self.mcp_url = mcp_url |
| 122 | self.llm_client = LLMClient(llm_config) |
| 123 | if mcp_client is not None: |
| 124 | self.mcp_client = mcp_client |
| 125 | else: |
| 126 | self.mcp_client = MCPClient( |
| 127 | url=mcp_url, tool_config_fp=tool_config_fp, session_id=session_id |
| 128 | ) |
| 129 | |
| 130 | # default writing text |
| 131 | self.mcp_fs_write = self.mcp_client.make_mcp_tool_function( |
| 132 | "fs_write", ["path", "content"] |
| 133 | ) |
| 134 | # default reading text |
| 135 | self.mcp_fs_read = self.mcp_client.make_mcp_tool_function( |
| 136 | "fs_read", ["path", "max_bytes"] |
| 137 | ) |
| 138 | |
| 139 | self.yaml_parser = None |
| 140 | self.tools = self.mcp_client.list_tools() |
| 141 | self.submodule_tools: List[Dict[str, Any]] = [] |
| 142 | self.submodule_registry: Dict[str, SubmoduleFunctionSpec] = {} |
| 143 | |
| 144 | # Initialize tokenizer (will be set based on model) |
| 145 | self.tokenizer = None |
| 146 | self.usage_tracker = { |
| 147 | "prompt_tokens_total": 0, |
| 148 | "completion_tokens_total": 0, |
| 149 | "reasoning_tokens_total": 0, |
| 150 | "cost_total": 0.0, |
| 151 | } |
| 152 | self.agent_interpreter: Interpreter = Interpreter( |
| 153 | self.mcp_client, self.tools, self.llm_client, self.usage_tracker |
| 154 | ) |
| 155 | |
| 156 | def _configure_tracing( |
| 157 | self, |
nothing calls this directly
no test coverage detected