12 Commits

Author SHA1 Message Date
Kazuhiro Sera 19e364c173 perf: speed up the test suite (#4171) 2026-08-04 08:35:55 +00:00
TheSaiEaranti a335b32024 fix: compare inspect sentinels by identity in function_schema (#3961) 2026-07-27 09:18:40 +09:00
TheSaiEaranti 99e88c14db fix: preserve *args/**kwargs docstring descriptions in tool schemas (#3956) 2026-07-26 08:29:45 +09:00
Myk b2e9246938 fix: parse Google docstrings whose Args: follows a section body (#3862) 2026-07-17 21:33:12 +09:00
Sohum Trivedi df20e83df3 fix: parse Google docstrings missing the blank line before a section (#3832) 2026-07-14 20:31:49 +00:00
Jonathan Haas c96de5e91e feat: support Annotated[T, Field(...)] in function schema (#2435) 2026-02-09 14:25:32 -08:00
Kazuhiro Sera aed6359047 feat: #1731 Enable developers to use Annotated types for function tool param description (#1753)
This pull request resolves #1731
2025-09-17 14:08:54 -04:00
Georg Wölflein 14154b78b6 feat(function_schema): Add support for pydantic Field annotations in tool arguments (for tools decorated with @function_schema) (#1124)
### Summary

This PR allows you to use the pydantic `Field` decorator to constrain
tool arguments for tools decorated with `@function_tool` (more
specifically, for tools using `function_schema` to parse tool
arguments). Such constrains include, e.g. limiting integers to a certain
range, but in principle, this should work for [any constrains supported
by the
API](https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses#supported-properties).

Specifically, it enables the following syntax:
```python
@function_tool
def my_tool(age: int = Field(..., gt=0)) -> str:
    ...
```

Previously, one had to create a nested pydantic `BaseModel` to achieve
this functionality.
Issue #1123 explains this feature request and the previous workaround.

**Example:**
```python
import json

from pydantic import Field

from agents import function_tool


@function_tool
def my_tool(age: int = Field(..., gt=0)) -> str:
    return f"The age is {age}"


print(json.dumps(my_tool.params_json_schema, indent=2))
```
**Output:** (compare to #1123)
```
{
  "properties": {
    "age": {
      "exclusiveMinimum": 0,
      "title": "Age",
      "type": "integer"
    }
  },
  "required": [
    "age"
  ],
  "title": "my_tool_args",
  "type": "object",
  "additionalProperties": false
}
```

### Test plan

I added unit tests in `tests/test_function_schema.py`.

### Issue number

Closes #1123.

### Checks

- [x] I've added new tests (if relevant)
- [ ] I've added/updated the relevant documentation
- [x] I've run `make lint` and `make format`
- [x] I've made sure tests pass

**Note:** I am happy to add documentation for this; please point me to
where I should do so:)
2025-07-15 11:35:54 -04:00
Rohan Mehta 6d2806f10c Fix function_schema name override bug (#872)
## Summary
- ensure `name_override` is always used in `function_schema`
- test name override when docstring info is disabled

## Testing
- `make format`
- `make lint`
- `make mypy`
- `make tests`

Resolves #860
------
https://chatgpt.com/codex/tasks/task_i_684f1cf885b08321b4dd3f4294e24ca2
2025-06-16 10:50:20 -04:00
Rohan Mehta bd404e0f87 Litellm integration (#524)
litellm is a library that abstracts away details/differences for a lot
of model providers. Adding an extension, so that any provider can easily
be integrated.

---
[//]: # (BEGIN SAPLING FOOTER)
* #532
* __->__ #524
2025-04-16 18:48:41 -04:00
Rohan Mehta 4854a745e8 Raise error on more invalid function schemas (#356)
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
2025-03-26 15:52:19 -04:00
Rohan Mehta aaec57a426 Initial commit 2025-03-11 09:42:28 -07:00