Skip to content

Instantly share code, notes, and snippets.

@pavlovmilen
Created May 11, 2025 10:38
Show Gist options
  • Save pavlovmilen/2e12d580dbd4d17d66d37ee65fe277fb to your computer and use it in GitHub Desktop.
Save pavlovmilen/2e12d580dbd4d17d66d37ee65fe277fb to your computer and use it in GitHub Desktop.
market_research_team_run
runtime = SingleThreadedAgentRuntime()
runtime.start()
message_count = 0
total_prompt_tokens = 0
total_completion_tokens = 0
async for message in market_reserarch_agents_team.run_stream(task="Hello, I would like to know if a stock with ticker=MSFT is a good pick for me to invest in this year?"):
if isinstance(message, TaskResult):
print("Stop Reason:", message.stop_reason)
if isinstance(message, BaseChatMessage):
message_count += 1
print(f'.................Message {message_count}.....................')
print(f"\033[93m........ Source: {message.source}\033[0m")
print(f"\033[94m{message.content}\033[0m")
if hasattr(message, 'models_usage') and message.models_usage is not None:
prompt = getattr(message.models_usage, 'prompt_tokens', 0)
completion = getattr(message.models_usage, 'completion_tokens', 0)
total_prompt_tokens += prompt
total_completion_tokens += completion
print(f"\033[91mInput tokens so far: {total_prompt_tokens}\033[0m")
print(f"\033[92mOutput tokens so far: {total_completion_tokens}\033[0m")
print(f"\033[91mTotal input tokens: {total_prompt_tokens}\033[0m")
print(f"\033[92mTotal output tokens: {total_completion_tokens}\033[0m")
await market_reserarch_agents_team.reset()
await runtime.stop()
print(f"\033[91mPrice of input tokens: £{total_prompt_tokens * 0.30 / 1000000}\033[0m")
print(f"\033[92mPrice of output tokens: £{total_completion_tokens * 1.20 / 1000000}\033[0m")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment