Squeezed in some additional features such as:
- updated get_version()
- various examples for streaming and non-streaming testing
Signed-off-by: Víctor Mayoral Vilches <v.mayoralv@gmail.com>
[Error occurred during streaming: 1 validation error for ResponseUsage
input_tokens_details
Input should be a valid dictionary or instance of InputTokensDetails [type=model_type, input_value=InputTokensDetails(prompt...ens=17, cached_tokens=0), input_type=InputTokensDetails]
For further information visit https://errors.pydantic.dev/2.10/v/model_type]
Location: Traceback (most recent call last):
File /Users/alias/Alias/research/openai-agents-python/src/cai/cli.py, line 209, in process_streamed_response
async for event in result.stream_events():
File /Users/alias/Alias/research/openai-agents-python/src/cai/sdk/agents/result.py, line 186, in stream_events
raise self._stored_exception
File /Users/alias/Alias/research/openai-agents-python/src/cai/sdk/agents/run.py, line 539, in _run_streamed_impl
turn_result = await cls._run_single_turn_streamed(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File /Users/alias/Alias/research/openai-agents-python/src/cai/sdk/agents/run.py, line 641, in _run_single_turn_streamed
async for event in model.stream_response(
File /Users/alias/Alias/research/openai-agents-python/src/cai/sdk/agents/models/openai_chatcompletions.py, line 421, in stream_response
ResponseUsage(
File /Users/alias/Alias/research/openai-agents-python/env/lib/python3.12/site-packages/pydantic/main.py, line 214, in __init__
validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for ResponseUsage
input_tokens_details
Input should be a valid dictionary or instance of InputTokensDetails [type=model_type, input_value=InputTokensDetails(prompt...ens=17, cached_tokens=0), input_type=InputTokensDetails]
For further information visit https://errors.pydantic.dev/2.10/v/model_type
Signed-off-by: Víctor Mayoral Vilches <v.mayoralv@gmail.com>
- agents can't translate directly it seems, see current error
- in addition, it appears streaming mode leads to other problems
Signed-off-by: Víctor Mayoral Vilches <v.mayoralv@gmail.com>
Towards #345
## Summary:
Using a `dict` or `Mapping` isn't strict-mode compliant. But we were
checking for the literal `True` whereas the value can also be an array,
for example. Fix that.
## Test Plan:
Unit tests
## Summary:
Adds tracing and tests for tracing.
- Tools are added to the agents
- Theres a span for the mcp tools lookup
- Functions have MCP data
## Test Plan:
Unit tests
.
## Summary:
Adds tracing and tests for tracing.
- Tools are added to the agents
- Theres a span for the mcp tools lookup
- Functions have MCP data
## Test Plan:
Unit tests
.
This pull request introduces functionality for visualizing agent
structures using Graphviz. The changes include adding a new dependency,
implementing functions to generate and draw graphs, and adding tests for
these functions.
New functionality for visualizing agent structures:
* Added `graphviz` as a new dependency in `pyproject.toml`.
* Implemented functions in `src/agents/visualizations.py` to generate
and draw graphs for agents using Graphviz. These functions include
`get_main_graph`, `get_all_nodes`, `get_all_edges`, and `draw_graph`.
Testing the new visualization functionality:
* Added tests in `tests/test_visualizations.py` to verify the
correctness of the graph generation and drawing functions. The tests
cover `get_main_graph`, `get_all_nodes`, `get_all_edges`, and
`draw_graph`.
For example, given the following code:
```python
from agents import Agent, function_tool
from agents.visualizations import draw_graph
@function_tool
def get_weather(city: str) -> str:
return f"The weather in {city} is sunny."
spanish_agent = Agent(
name="Spanish agent",
instructions="You only speak Spanish.",
)
english_agent = Agent(
name="English agent",
instructions="You only speak English",
)
triage_agent = Agent(
name="Triage agent",
instructions="Handoff to the appropriate agent based on the language of the request.",
handoffs=[spanish_agent, english_agent],
tools=[get_weather],
)
draw_graph(triage_agent)
```
Generates the following image:
<img width="614" alt="Screenshot 2025-03-13 at 18 36 23"
src="https://github.com/user-attachments/assets/d01fe502-6886-4efb-aaf8-c92e4524b0fe"
/>