Feat/tool based coordinator routing (#5)
Co-authored-by: Michael <michael@example.com> Reviewed-on: #5
This commit is contained in:
+10
-3
@@ -5,6 +5,8 @@ from typing import Any, Callable
|
||||
from .prompt import CAVEMAN_PROMPT
|
||||
from .coding_prompt import CODING_AGENT_SYSTEM_PROMPT
|
||||
|
||||
logger: logging.Logger = logging.getLogger("agent-coding")
|
||||
|
||||
|
||||
class _ActResponseCapture:
|
||||
"""Captures the AI response from LMStudio act() callback."""
|
||||
@@ -62,6 +64,7 @@ class CodingAgent:
|
||||
|
||||
async def initialize(self) -> None:
|
||||
"""Initialize the LM Studio model."""
|
||||
logger.info(f"Initializing CodingAgent with model: {self.model_name}")
|
||||
self.model = lms.llm(self.model_name)
|
||||
|
||||
async def run(self, user_input: str) -> str:
|
||||
@@ -76,9 +79,12 @@ class CodingAgent:
|
||||
]
|
||||
|
||||
try:
|
||||
logger.info(f"Running CodingAgent interactively (input length: {len(user_input)})")
|
||||
response = await self.model.respond(user_input, messages=messages)
|
||||
logger.info(f"CodingAgent responded successfully (response length: {len(response)})")
|
||||
return response
|
||||
except Exception as e:
|
||||
logger.error(f"CodingAgent execution error: {e}")
|
||||
return f"Error in agent execution: {str(e)}"
|
||||
|
||||
async def run_with_tools(self, user_input: str, tools: list[Callable[..., Any]]) -> str:
|
||||
@@ -89,13 +95,14 @@ class CodingAgent:
|
||||
|
||||
try:
|
||||
capture = _ActResponseCapture()
|
||||
logger: logging.Logger = logging.getLogger("agent-coding")
|
||||
logger.info(f"Calling LMStudio act() with {len(tools)} tools...")
|
||||
logger.info(f"Calling LMStudio act() on CodingAgent with {len(tools)} tools...")
|
||||
result: lms.ActResult = self.model.act(user_input, tools=tools, on_message=capture)
|
||||
logger.info(f"act() returned: {result}")
|
||||
logger.info(f"act() on CodingAgent returned: {result}")
|
||||
response: str = capture.full_response
|
||||
if not response or response == "No response captured.":
|
||||
logger.warning(f"Act completed with {result.rounds} rounds but no response was captured.")
|
||||
return f"Act completed with {result.rounds} rounds but no response captured."
|
||||
return response
|
||||
except Exception as e:
|
||||
logger.error(f"CodingAgent tool execution error: {e}")
|
||||
return f"Error in agent tool execution: {str(e)}"
|
||||
|
||||
Reference in New Issue
Block a user