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

Add GraphRun object to make use of next more ergonomic #833

Open
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

dmontagu
Copy link
Contributor

@dmontagu dmontagu commented Feb 1, 2025

This is the result of trying to reduce the amount of stuff happening in Graph.run that wasn't just in next.

It's now in a pretty good state, it does the thing we discussed of implementing __await__, __anext__, and async def next to provide a way to async iterate over the result of calling agent.run, hijack the execution with next, or just await it to get the output without iteration.

@dmontagu dmontagu changed the title Dmontagu/graph run object Add GraphRun object Feb 1, 2025
@dmontagu dmontagu changed the title Add GraphRun object Add GraphRun object to make use of next more ergonomic Feb 1, 2025
@github-actions github-actions bot temporarily deployed to deploy-preview February 1, 2025 00:55 Inactive
@dmontagu dmontagu mentioned this pull request Feb 1, 2025
@dmontagu dmontagu force-pushed the dmontagu/graph-run-object branch from 6ce755e to 571d805 Compare February 1, 2025 01:08
@dmontagu dmontagu changed the base branch from main to dmontagu/stream-tool-calls February 1, 2025 01:09
@dmontagu dmontagu force-pushed the dmontagu/stream-tool-calls branch from 1443b49 to c4e9180 Compare February 1, 2025 01:09
@dmontagu dmontagu force-pushed the dmontagu/graph-run-object branch from 571d805 to 04fc74c Compare February 1, 2025 01:10
@github-actions github-actions bot temporarily deployed to deploy-preview February 1, 2025 01:13 Inactive
@dmontagu dmontagu marked this pull request as ready for review February 3, 2025 21:23
@github-actions github-actions bot temporarily deployed to deploy-preview February 3, 2025 21:30 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview February 3, 2025 22:01 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview February 3, 2025 22:17 Inactive
@dmontagu dmontagu force-pushed the dmontagu/graph-run-object branch from 39a6009 to 2621543 Compare February 3, 2025 22:47
@github-actions github-actions bot temporarily deployed to deploy-preview February 3, 2025 22:50 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview February 3, 2025 23:50 Inactive
@dmontagu dmontagu force-pushed the dmontagu/graph-run-object branch from 873fe35 to e4d384a Compare February 5, 2025 20:16
@github-actions github-actions bot temporarily deployed to deploy-preview February 5, 2025 20:20 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview February 6, 2025 15:38 Inactive
Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks good, but obviously needs more work, and will conflict with #824.

pydantic_ai_slim/pydantic_ai/models/openai.py Outdated Show resolved Hide resolved
pydantic_graph/pydantic_graph/graph.py Show resolved Hide resolved
pydantic_graph/pydantic_graph/graph.py Outdated Show resolved Hide resolved
pydantic_graph/pydantic_graph/graph.py Outdated Show resolved Hide resolved
pydantic_graph/pydantic_graph/graph.py Outdated Show resolved Hide resolved
pydantic_graph/pydantic_graph/graph.py Outdated Show resolved Hide resolved
pydantic_graph/pydantic_graph/graph.py Outdated Show resolved Hide resolved
docs/graph.md Show resolved Hide resolved
pydantic_ai_slim/pydantic_ai/agent.py Outdated Show resolved Hide resolved
pydantic_ai_slim/pydantic_ai/messages.py Outdated Show resolved Hide resolved
@dmontagu dmontagu force-pushed the dmontagu/graph-run-object branch from aa74a7c to bc681bc Compare February 6, 2025 22:50
@github-actions github-actions bot temporarily deployed to deploy-preview February 6, 2025 22:54 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview February 6, 2025 23:07 Inactive
@dmontagu dmontagu force-pushed the dmontagu/graph-run-object branch from 17409cc to 0b93143 Compare February 10, 2025 21:15
@github-actions github-actions bot temporarily deployed to deploy-preview February 10, 2025 21:18 Inactive
Copy link
Contributor

@hyperlint-ai hyperlint-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The style guide flagged several spelling errors that seemed like false positives. We skipped posting inline suggestions for the following words:

  • [Ii]terable
  • [Aa]sync
  • [Cc]oroutine
  • [Dd]eps

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is looking good.

I'm still a bit lost about iterating combined with streaming.

docs/agents.md Outdated Show resolved Hide resolved
docs/agents.md Outdated Show resolved Hide resolved
docs/agents.md Outdated Show resolved Hide resolved
docs/agents.md Outdated Show resolved Hide resolved
docs/agents.md Outdated Show resolved Hide resolved
docs/graph.md Outdated Show resolved Hide resolved
docs/graph.md Outdated Show resolved Hide resolved
pydantic_ai_slim/pydantic_ai/agent.py Outdated Show resolved Hide resolved
pydantic_ai_slim/pydantic_ai/agent.py Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be public since the nodes you get from iterating are now kind of public?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's enough to leave the module private and re-export the node classes, but I'm also okay to make the module public.

Copy link
Contributor Author

@dmontagu dmontagu Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've done the re-export thing now, and it works for me in pycharm, but it might be worth double-checking on your end

Copy link
Contributor

@hyperlint-ai hyperlint-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The style guide flagged several spelling errors that seemed like false positives. We skipped posting inline suggestions for the following words:

  • [Ii]nherited_members

@github-actions github-actions bot temporarily deployed to deploy-preview February 18, 2025 18:21 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview February 18, 2025 20:50 Inactive
docs/agents.md Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to deploy-preview February 18, 2025 21:33 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview February 19, 2025 01:36 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview February 19, 2025 03:54 Inactive
@dmontagu dmontagu mentioned this pull request Feb 19, 2025
Copy link

github-actions bot commented Feb 20, 2025

Docs Preview

commit: c7ab89f
Preview URL: https://15219b05-pydantic-ai-previews.pydantic.workers.dev

@dmontagu dmontagu force-pushed the dmontagu/graph-run-object branch from 6460a73 to 241f179 Compare February 20, 2025 03:55
Comment on lines +42 to +47
# Re-exporting like this improves auto-import behavior in PyCharm
capture_run_messages = _agent_graph.capture_run_messages
EndStrategy = _agent_graph.EndStrategy
HandleResponseNode = _agent_graph.HandleResponseNode
ModelRequestNode = _agent_graph.ModelRequestNode
UserPromptNode = _agent_graph.UserPromptNode
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samuelcolvin let me know if you think there's a better way to do this. (I tried other things I could think of and this worked best.)

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

Successfully merging this pull request may close these issues.

3 participants