MCPcopy Create free account
hub / github.com/ScaleML/AgentSPEX / Interpreter

Class Interpreter

src/harness/execution/interpreter.py:65–362  ·  view source on GitHub ↗

Main interpreter for executing YAML workflow steps. This class provides the dispatch logic for executing workflow steps, delegating actual step execution to handler methods inherited from StepHandlersMixin. Attributes: mcp_client: MCP client for tool invocation.

Source from the content-addressed store, hash-verified

63
64
65class Interpreter(StepHandlersMixin):
66 """
67 Main interpreter for executing YAML workflow steps.
68
69 This class provides the dispatch logic for executing workflow steps,
70 delegating actual step execution to handler methods inherited from
71 StepHandlersMixin.
72
73 Attributes:
74 mcp_client: MCP client for tool invocation.
75 tools: List of available tool definitions.
76 llm_executor: LLMExecutor for running LLM completions.
77 mcp_fs_write: Convenience function for writing files.
78 mcp_fs_read: Convenience function for reading files.
79
80 Example:
81 interpreter = Interpreter(mcp_client, tools, openai_client)
82 output, tokens = interpreter.execute_workflow_step(
83 step_data, context, step_number, args, logger
84 )
85 """
86
87 def __init__(self, mcp_client, tools, llm_client, usage_tracker=None):
88 """
89 Initialize the interpreter.
90
91 Args:
92 mcp_client: MCP client for tool invocation.
93 tools: List of available tools.
94 llm_client: LLMClient for LLM calls (supports multiple providers via LiteLLM).
95 usage_tracker: Optional dict for tracking token usage.
96 If None, creates a default tracker.
97 """
98 if usage_tracker is None:
99 usage_tracker = {
100 "prompt_tokens_total": 0,
101 "completion_tokens_total": 0,
102 "reasoning_tokens_total": 0,
103 "cost_total": 0.0,
104 }
105
106 self.mcp_client = mcp_client
107 self.tools = tools
108
109 # Convenience functions for file operations
110 self.mcp_fs_write = self.mcp_client.make_mcp_tool_function(
111 "fs_write", ["path", "content"]
112 )
113 self.mcp_fs_read = self.mcp_client.make_mcp_tool_function(
114 "fs_read", ["path", "max_bytes"]
115 )
116
117 self.llm_executor: LLMExecutor = LLMExecutor(
118 mcp_client=mcp_client,
119 tools=tools,
120 llm_client=llm_client,
121 usage_tracker=usage_tracker,
122 )

Callers 2

executeMethod · 0.90
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected