From 0a76ece24994a2fe16ae631254686af97e42b631 Mon Sep 17 00:00:00 2001 From: Ashwin Bharambe Date: Mon, 3 Mar 2025 16:15:47 -0800 Subject: [PATCH] feat: add more logs to agent_instance.py --- llama_stack/distribution/resolver.py | 1 - llama_stack/distribution/server/server.py | 2 +- .../agents/meta_reference/agent_instance.py | 21 ++++++++++--------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/llama_stack/distribution/resolver.py b/llama_stack/distribution/resolver.py index acbbee09d..c24df384d 100644 --- a/llama_stack/distribution/resolver.py +++ b/llama_stack/distribution/resolver.py @@ -247,7 +247,6 @@ def sort_providers_by_deps( logcat.debug("core", f"Resolved {len(sorted_providers)} providers") for api_str, provider in sorted_providers: logcat.debug("core", f" {api_str} => {provider.provider_id}") - logcat.debug("core", "") return sorted_providers diff --git a/llama_stack/distribution/server/server.py b/llama_stack/distribution/server/server.py index 4b70e0087..aee30bbe6 100644 --- a/llama_stack/distribution/server/server.py +++ b/llama_stack/distribution/server/server.py @@ -436,7 +436,7 @@ def main(): ) ) - logcat.debug("server", f"Serving API {api_str}") + logcat.debug("server", f"serving APIs: {apis_to_serve}") app.exception_handler(RequestValidationError)(global_exception_handler) app.exception_handler(Exception)(global_exception_handler) diff --git a/llama_stack/providers/inline/agents/meta_reference/agent_instance.py b/llama_stack/providers/inline/agents/meta_reference/agent_instance.py index 34a9db630..7a6cc551b 100644 --- a/llama_stack/providers/inline/agents/meta_reference/agent_instance.py +++ b/llama_stack/providers/inline/agents/meta_reference/agent_instance.py @@ -6,7 +6,6 @@ import copy import json -import logging import os import re import secrets @@ -18,6 +17,7 @@ from urllib.parse import urlparse import httpx +from llama_stack import logcat from llama_stack.apis.agents import ( AgentConfig, AgentToolGroup, @@ -79,8 +79,6 @@ from llama_stack.providers.utils.telemetry import tracing from .persistence import AgentPersistence from .safety import SafetyException, ShieldRunnerMixin -log = logging.getLogger(__name__) - def make_random_string(length: int = 8): return "".join(secrets.choice(string.ascii_letters + string.digits) for _ in range(length)) @@ -219,8 +217,9 @@ class ChatAgent(ShieldRunnerMixin): toolgroups_for_turn=request.toolgroups, ): if isinstance(chunk, CompletionMessage): - log.info( - f"{chunk.role.capitalize()}: {chunk.content}", + logcat.info( + "agents", + f"returning result from the agent turn: {chunk}", ) output_message = chunk continue @@ -665,7 +664,7 @@ class ChatAgent(ShieldRunnerMixin): ) if n_iter >= self.agent_config.max_infer_iters: - log.info("Done with MAX iterations, exiting.") + logcat.info("agents", f"done with MAX iterations ({n_iter}), exiting.") # NOTE: mark end_of_turn to indicate to client that we are done with the turn # Do not continue the tool call loop after this point message.stop_reason = StopReason.end_of_turn @@ -673,7 +672,7 @@ class ChatAgent(ShieldRunnerMixin): break if stop_reason == StopReason.out_of_tokens: - log.info("Out of token budget, exiting.") + logcat.info("agents", "out of token budget, exiting.") yield message break @@ -687,10 +686,10 @@ class ChatAgent(ShieldRunnerMixin): message.content = [message.content] + output_attachments yield message else: - log.info(f"Partial message: {str(message)}") + logcat.debug("agents", f"completion message with EOM (iter: {n_iter}): {str(message)}") input_messages = input_messages + [message] else: - log.info(f"{str(message)}") + logcat.debug("agents", f"completion message (iter: {n_iter}) from the model: {str(message)}") # 1. Start the tool execution step and progress step_id = str(uuid.uuid4()) yield AgentTurnResponseStreamChunk( @@ -1042,7 +1041,7 @@ async def attachment_message(tempdir: str, urls: List[URL]) -> ToolResponseMessa path = urlparse(uri).path basename = os.path.basename(path) filepath = f"{tempdir}/{make_random_string() + basename}" - log.info(f"Downloading {url} -> {filepath}") + logcat.info("agents", f"Downloading {url} -> {filepath}") async with httpx.AsyncClient() as client: r = await client.get(uri) @@ -1082,6 +1081,7 @@ async def execute_tool_call_maybe( else: name = name.value + logcat.info("agents", f"executing tool call: {name} with args: {tool_call.arguments}") result = await tool_runtime_api.invoke_tool( tool_name=name, kwargs={ @@ -1091,6 +1091,7 @@ async def execute_tool_call_maybe( **toolgroup_args.get(group_name, {}), }, ) + logcat.debug("agents", f"tool call {name} completed with result: {result}") return result