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

tools work with agent.run() but do not work with agent.run_stream() #957

Open
gmankab opened this issue Feb 20, 2025 · 2 comments
Open

tools work with agent.run() but do not work with agent.run_stream() #957

gmankab opened this issue Feb 20, 2025 · 2 comments

Comments

@gmankab
Copy link

gmankab commented Feb 20, 2025

reproducing my problem:

  • uv pip install pydantic-ai-slim==0.0.24
  • run dice.game.py from https://ai.pydantic.dev/tools
  • everything work
  • make it use agent.run_stream() instead of agent.run()
import asyncio
import random
from pydantic_ai import Agent, RunContext

agent = Agent(
    'google-gla:gemini-1.5-flash',
    deps_type=str,
    system_prompt=(
        "You're a dice game, you should roll the die and see if the number "
        "you get back matches the user's guess. If so, tell them they're a winner. "
        "Use the player's name in the response."
    ),
)


@agent.tool_plain
def roll_die() -> str:
    """Roll a six-sided die and return the result."""
    return str(random.randint(1, 6))


@agent.tool
def get_player_name(ctx: RunContext[str]) -> str:
    """Get the player's name."""
    return ctx.deps


async def main():
    async with agent.run_stream('My guess is 4', deps='Anne') as result:
        async for chunk in result.stream_text():
            print(chunk)
asyncio.run(main())
  • tools are no longer work
@gmankab
Copy link
Author

gmankab commented Feb 20, 2025

may be related - #640

@WorldInnovationsDepartment

I think it will be fixed in .next refactor. Am I right @dmontagu ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants