Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support StructuredTool #121

Closed
lgesuellip opened this issue Dec 2, 2024 · 2 comments · Fixed by #128
Closed

Support StructuredTool #121

lgesuellip opened this issue Dec 2, 2024 · 2 comments · Fixed by #128

Comments

@lgesuellip
Copy link

lgesuellip commented Dec 2, 2024

Hi Team,

At Pampa, we're currently testing a new framework and need to implement a StructuredTool class, similar to LangChain's StructuredTool. This class would encapsulate any function, allowing it to be used seamlessly by an agent while maintaining a clear input/output schema (BaseModel).

Our goal is to use this to wrap the tool definitions for an API. By defining clear input and output schemas, we’re creating a structured and standardized approach for interacting with the API. You can see this in the following example, we have a generic function and we have available the schemas.

def tool_util(client, tool_id):

  # Wrapper function to execute
  def tool_wrapper(*args, **kwargs):
    response = client.tools.execute(
      tool_name=tool_id,
      inputs=kwargs,
    )
    return response

  # Get tool definition
  tool_def = client.tools.get(tool_id=tool_id)

  # Create and return the structured tool
  return StructuredTool.from_function(
    func=tool_wrapper,
    name=tool_name,
    description=description,
    args_schema=args_schema
  )

Currently, I am exploring the implementation by inheriting from the Tool class. Do you have any recommendations or best practices for implementing this functionality?

Thanks,

@lgesuellip lgesuellip changed the title StructuredTool Support StructuredTool Dec 2, 2024
@samuelcolvin
Copy link
Member

Hi @lgesuellip, you don't need to inherit from Tool, especially as it's currently private and it's signature may change.

As part of #110 I'm intending to expose Tool as a reusable wrapper for tools, but until then, I think you can just create functions and reuse them, e.g.

async def my_tool(a: int, b: str) -> str:
    return f'{a}<>{b}'

agent1 = Agent()
agent1.tool(my_tool)

agent2 = Agent()
agent2.tool(my_tool)

@lgesuellip
Copy link
Author

Thank you @samuelcolvin , it looks promising!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants