mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-09 12:17:24 -04:00
fix: make ContextInjector async to match ToolCallInterceptor protocol
The interceptor __call__ method must be async and follow the proper signature: async __call__(request, handler) -> result Previous implementation was synchronous and had wrong signature, causing 'object function can't be used in await expression' error.
This commit is contained in:
@@ -5,7 +5,7 @@ This interceptor automatically injects `signature` and `today_date` parameters
|
|||||||
into buy/sell tool calls to support concurrent multi-model simulations.
|
into buy/sell tool calls to support concurrent multi-model simulations.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import Any, Dict
|
from typing import Any, Callable, Awaitable
|
||||||
|
|
||||||
|
|
||||||
class ContextInjector:
|
class ContextInjector:
|
||||||
@@ -28,23 +28,28 @@ class ContextInjector:
|
|||||||
self.signature = signature
|
self.signature = signature
|
||||||
self.today_date = today_date
|
self.today_date = today_date
|
||||||
|
|
||||||
def __call__(self, tool_name: str, tool_input: Dict[str, Any]) -> Dict[str, Any]:
|
async def __call__(
|
||||||
|
self,
|
||||||
|
request: Any, # MCPToolCallRequest
|
||||||
|
handler: Callable[[Any], Awaitable[Any]]
|
||||||
|
) -> Any: # MCPToolCallResult
|
||||||
"""
|
"""
|
||||||
Intercept tool call and inject context parameters.
|
Intercept tool call and inject context parameters.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
tool_name: Name of the tool being called
|
request: Tool call request containing name and arguments
|
||||||
tool_input: Original tool input parameters
|
handler: Async callable to execute the actual tool
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Modified tool input with injected context
|
Result from handler after injecting context
|
||||||
"""
|
"""
|
||||||
# Only inject for trade tools (buy/sell)
|
# Inject signature and today_date for trade tools
|
||||||
if tool_name in ["buy", "sell"]:
|
if request.name in ["buy", "sell"]:
|
||||||
# Inject signature and today_date if not already provided
|
# Add signature and today_date to arguments if not present
|
||||||
if "signature" not in tool_input:
|
if "signature" not in request.arguments:
|
||||||
tool_input["signature"] = self.signature
|
request.arguments["signature"] = self.signature
|
||||||
if "today_date" not in tool_input:
|
if "today_date" not in request.arguments:
|
||||||
tool_input["today_date"] = self.today_date
|
request.arguments["today_date"] = self.today_date
|
||||||
|
|
||||||
return tool_input
|
# Call the actual tool handler
|
||||||
|
return await handler(request)
|
||||||
|
|||||||
Reference in New Issue
Block a user