Commit graph

7 commits

Author SHA1 Message Date
Rohan Mehta
2b9b8f7e73
Prompts support (#876)
Add support for the new openai prompts feature.
2025-06-16 15:47:48 -04:00
Rohan Mehta
0eee6b8305
Allow arbitrary kwargs in model (#842)
Sometimes users want to provide parameters specific to a model provider.
This is an escape hatch.
2025-06-10 18:14:34 -04:00
Rohan Mehta
d4c7a23e1d
Don't cache agent tools during a run (#803)
### Summary:
Towards #767. We were caching the list of tools for an agent, so if you
did `agent.tools.append(...)` from a tool call, the next call to the
model wouldn't include the new tool. THis is a bug.

### Test Plan:
Unit tests. Note that now MCP tools are listed each time the agent runs
(users can still cache the `list_tools` however).
2025-06-02 14:49:16 -04:00
WJPBProjects
466b44df18
Dev/add usage details to Usage class (#726)
PR to enhance the `Usage` object and related logic, to support more
granular token accounting, matching the details available in the [OpenAI
Responses API](https://platform.openai.com/docs/api-reference/responses)
. Specifically, it:

- Adds `input_tokens_details` and `output_tokens_details` fields to the
`Usage` dataclass, storing detailed token breakdowns (e.g.,
`cached_tokens`, `reasoning_tokens`).
- Flows this change through
- Updates and extends tests to match
- Adds a test for the Usage.add method

### Motivation
- Aligns the SDK’s usage with the latest OpenAI responses API Usage
object
- Supports downstream use cases that require fine-grained token usage
data (e.g., billing, analytics, optimization) requested by startups

---------

Co-authored-by: Wulfie Bain <wulfie@openai.com>
2025-05-20 18:23:56 +01:00
Ashok Saravanan
1994f9d4c4
feat: pass extra_body through to LiteLLM acompletion (#638)
**Purpose**  
Allow arbitrary `extra_body` parameters (e.g. `cached_content`) to be
forwarded into the LiteLLM call. Useful for context caching in Gemini
models
([docs](https://ai.google.dev/gemini-api/docs/caching?lang=python)).

**Example usage**  
```python
import os
from agents import Agent, ModelSettings
from agents.extensions.models.litellm_model import LitellmModel

cache_name = "cachedContents/34jopukfx5di"  # previously stored context

gemini_model = LitellmModel(
    model="gemini/gemini-1.5-flash-002",
    api_key=os.getenv("GOOGLE_API_KEY")
)

agent = Agent(
    name="Cached Gemini Agent",
    model=gemini_model,
    model_settings=ModelSettings(
        extra_body={"cached_content": cache_name}
    )
)
2025-05-14 12:34:27 -04:00
Daniele Morotti
e11b822d5f
Fix stream error using LiteLLM (#589)
In response to issue #587 , I implemented a solution to first check if
`refusal` and `usage` attributes exist in the `delta` object.

I added a unit test similar to `test_openai_chatcompletions_stream.py`.

Let me know if I should change something.

---------

Co-authored-by: Rohan Mehta <rm@openai.com>
2025-04-24 12:53:39 -04:00
Rohan Mehta
942ba9840b
Docs and tests for litellm (#561) 2025-04-21 16:59:01 -04:00