### 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:)
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
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