Compare commits

...

4 Commits

Author SHA1 Message Date
Brandon Hancock
44217b1e5b add back in docstring 2024-10-25 17:58:45 -04:00
Brandon Hancock
430a2038a3 Drop print 2024-10-25 16:02:31 -04:00
Brandon Hancock
6df3758770 fix lint 2024-10-25 15:42:41 -04:00
Brandon Hancock
05cd56ca54 improve tool text descriptoin and args 2024-10-25 15:37:38 -04:00

View File

@@ -1,7 +1,6 @@
import os import os
import shutil import shutil
import subprocess import subprocess
from inspect import signature
from typing import Any, List, Literal, Optional, Union from typing import Any, List, Literal, Optional, Union
from pydantic import Field, InstanceOf, PrivateAttr, model_validator from pydantic import Field, InstanceOf, PrivateAttr, model_validator
@@ -395,26 +394,26 @@ class Agent(BaseAgent):
def _render_text_description_and_args(self, tools: List[Any]) -> str: def _render_text_description_and_args(self, tools: List[Any]) -> str:
"""Render the tool name, description, and args in plain text. """Render the tool name, description, and args in plain text.
Output will be in the format of: Output will be in the format of:
.. code-block:: markdown .. code-block:: markdown
search: This tool is used for search, args: {"query": {"type": "string"}} search: This tool is used for search, args: {"query": {"type": "string"}}
calculator: This tool is used for math, \ calculator: This tool is used for math, \
args: {"expression": {"type": "string"}} args: {"expression": {"type": "string"}}
""" """
tool_strings = [] tool_strings = []
for tool in tools: for tool in tools:
args_schema = str(tool.model_fields) args_schema = {
if hasattr(tool, "func") and tool.func: name: {
sig = signature(tool.func) "description": field.description,
description = ( "type": field.annotation.__name__,
f"Tool Name: {tool.name}{sig}\nTool Description: {tool.description}" }
) for name, field in tool.args_schema.model_fields.items()
else: }
description = ( description = (
f"Tool Name: {tool.name}\nTool Description: {tool.description}" f"Tool Name: {tool.name}\nTool Description: {tool.description}"
) )
tool_strings.append(f"{description}\nTool Arguments: {args_schema}") tool_strings.append(f"{description}\nTool Arguments: {args_schema}")
return "\n".join(tool_strings) return "\n".join(tool_strings)