Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set logging of internal messages to debug #3694

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _format_chat_message(

def emit(self, record: logging.LogRecord) -> None:
ts = datetime.fromtimestamp(record.created).isoformat()
if isinstance(record.msg, ContentPublishEvent | ToolCallEvent | ToolCallResultEvent):
if isinstance(record.msg, ContentPublishEvent):
sys.stdout.write(
self._format_chat_message(
source_agent_id=record.msg.source,
Expand All @@ -71,6 +71,20 @@ def emit(self, record: logging.LogRecord) -> None:
)
)
sys.stdout.flush()
elif isinstance(record.msg, ToolCallEvent):
sys.stdout.write(
f"\n{'-'*75} \n"
f"\033[91m[{ts}], Tool Call:\033[0m\n"
f"\n{self.serialize_content(record.msg.agent_message)}"
)
sys.stdout.flush()
elif isinstance(record.msg, ToolCallResultEvent):
sys.stdout.write(
f"\n{'-'*75} \n"
f"\033[91m[{ts}], Tool Call Result:\033[0m\n"
f"\n{self.serialize_content(record.msg.agent_message)}"
)
sys.stdout.flush()
elif isinstance(record.msg, SelectSpeakerEvent):
sys.stdout.write(
f"\n{'-'*75} \n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def handle_content_request(self, message: ContentRequestEvent, ctx: Messag
# Handle tool calls.
while isinstance(response, ToolCallMessage):
# Log the tool call.
event_logger.info(ToolCallEvent(agent_message=response, source=self.id))
event_logger.debug(ToolCallEvent(agent_message=response, source=self.id))

results: List[FunctionExecutionResult | BaseException] = await asyncio.gather(
*[
Expand All @@ -79,7 +79,7 @@ async def handle_content_request(self, message: ContentRequestEvent, ctx: Messag
# Create a new tool call result message.
feedback = ToolCallResultMessage(content=function_results, source=self._tool_agent_id.type)
# Log the feedback.
event_logger.info(ToolCallResultEvent(agent_message=feedback, source=self._tool_agent_id))
event_logger.debug(ToolCallResultEvent(agent_message=feedback, source=self._tool_agent_id))
response = await self._agent.on_messages([feedback], ctx.cancellation_token)

# Publish the response.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async def select_speaker(self, thread: List[ContentPublishEvent]) -> str:
else:
agent_name = participants[0]
self._previous_speaker = agent_name
event_logger.info(SelectSpeakerEvent(selected_speaker=agent_name, source=self.id))
event_logger.debug(SelectSpeakerEvent(selected_speaker=agent_name, source=self.id))
return agent_name

def _mentioned_agents(self, message_content: str, agent_names: List[str]) -> Dict[str, int]:
Expand Down
Loading