feat: tool generation improvements (#3633)

This commit is contained in:
cthomas
2025-07-29 15:35:08 -07:00
committed by GitHub
parent 064951bfe6
commit c48945a54c
2 changed files with 8 additions and 7 deletions

View File

@@ -34,7 +34,7 @@ You are are expert python programmer that is tasked with generating python sourc
**Quick Rules for Generation**
1. **Use a flat, one-line signature** with only native types:
```python
def tool_name(param1: str, flag: bool = True) -> dict:
def tool_name(param1: str, flag: bool) -> dict:
```
2. **Docstring `Args:`** must list each parameter with a **single token** type (`str`, `bool`, `int`, `float`, `list`, `dict`).
3. **Avoid** `Union[...]`, `List[...]`, multi-line signatures, or pipes in types.
@@ -50,7 +50,7 @@ You are are expert python programmer that is tasked with generating python sourc
Example:
```python
def get_price(coin_ids: str, vs_currencies: str, include_market_cap: bool) -> dict:
def get_price(coin_ids: str, vs_currencies: str, reverse: bool) -> list:
```
</tool_signature>
@@ -62,17 +62,17 @@ A docstring must always be generated and formatted correctly as part of any gene
Example:
```python
def get_price(coin_ids: str, vs_currencies: str, include_market_cap: bool) -> dict:
def get_price(coin_ids: str, vs_currencies: str, reverse: bool) -> list:
"""
Fetch prices from CoinGecko.
Args:
coin_ids (str): Comma-separated CoinGecko IDs.
vs_currencies (str): Comma-separated target currencies.
include_market_cap (bool): Include market-cap data.
reverse (bool): Reverse the order of the coin_ids for the output list.
Returns:
dict: Result with a key for each specified coin_id where the value is a nested dict with the price in the target currency and optional market_cap.
list: the prices in the target currency, in the same order as the coin_ids if reverse is False, otherwise in the reverse order
"""
...
```
@@ -106,13 +106,14 @@ def get_price(coin_ids: str, vs_currencies: str, include_market_cap: bool) -> di
<tool_sample_args>
- **Required** to be generated on every turn so solution can be tested successfully.
- **Must** be valid JSON string, where each key is the name of an argument and each value is the proposed value for that argument, as a string.
- **Infer** values from the conversation with the user when possible so they values are aligned with their use case.
Example:
```JSON
{
"coin_ids": "bitcoin,ethereum",
"vs_currencies": "usd",
"include_market_cap": "true"
"reverse": "False"
}
```
</tool_sample_args>

View File

@@ -971,7 +971,7 @@ async def generate_tool_from_prompt(
response_data = await llm_client.request_async(request_data, llm_config)
response = llm_client.convert_response_to_chat_completion(response_data, input_messages, llm_config)
output = json.loads(response.choices[0].message.tool_calls[0].function.arguments)
pip_requirements = [PipRequirement(name=k, version=v) for k, v in json.loads(output["pip_requirements_json"]).items()]
pip_requirements = [PipRequirement(name=k, version=v or None) for k, v in json.loads(output["pip_requirements_json"]).items()]
return GenerateToolOutput(
tool=Tool(
name=request.tool_name,