Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: tool generation improvements (#3633)
cthomas6f3afbb2e116
diff --git a/letta/prompts/system/memgpt_generate_tool.txt b/letta/prompts/system/memgpt_generate_tool.txtindex 826b578b0..17a9353a8 100644--- a/letta/prompts/system/memgpt_generate_tool.txt+++ b/letta/prompts/system/memgpt_generate_tool.txt@@ -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 sourcExample:```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 geneExample:```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>diff --git a/letta/server/rest_api/routers/v1/tools.py b/letta/server/rest_api/routers/v1/tools.pyindex 45bd4e046..4f47470ee 100644--- a/letta/server/rest_api/routers/v1/tools.py+++ b/letta/server/rest_api/routers/v1/tools.py@@ -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,