Skip to content

agent: Add Agent AsyncEventLogger #218

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all 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
10 changes: 9 additions & 1 deletion src/llama_stack_client/lib/agents/event_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This source code is licensed under the terms described in the LICENSE file in
# the root directory of this source tree.

from typing import Any, Iterator, Optional, Tuple
from typing import Any, AsyncIterator, Iterator, Optional, Tuple

from termcolor import cprint

Expand Down Expand Up @@ -163,3 +163,11 @@ def log(self, event_generator: Iterator[Any]) -> Iterator[TurnStreamPrintableEve
printer = TurnStreamEventPrinter()
for chunk in event_generator:
yield from printer.yield_printable_events(chunk)


class AsyncEventLogger:
async def log(self, event_generator: AsyncIterator[Any]) -> AsyncIterator[TurnStreamPrintableEvent]:
printer = TurnStreamEventPrinter()
async for chunk in event_generator:
for printable_event in printer.yield_printable_events(chunk):
yield printable_event