crewAIInc / crewAI

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
https://crewai.com
MIT License
18.93k stars 2.61k forks source link

CrewAI - Langchain StructuredTool JSON markdown string as input #923

Open ChristianJohnston97 opened 1 month ago

ChristianJohnston97 commented 1 month ago

I have a custom tool using the langchain StructuredTool.from_function

from langchain.tools.base import StructuredTool
from langchain_core.pydantic_v1 import BaseModel, Field

create_draft_tool = StructuredTool.from_function(
func=create_draft,
name="Create Draft",
description="""
    Create an email draft. Ensure to pass input as a valid JSON.
    Only pass in a JSON object. Do not pass in any markdown string anywhere.
""",
args_schema=DraftInput,
return_direct=True
)

where DraftInput is a Pydantic class (fields excluded)

class DraftInput(BaseModel):
  to: str = Field(
      ...,
      description="Who to send the email to",
      alias="to"
  )

but when the tool is called, it passes in the correct JSON but inside a markdown string like so:

Action: Create Draft
Action Input:
```json
   {
     "to": "<email>"
   }
```.

and so the tool fails with the error Task output: Error: the Action Input is not a valid key, value dictionary.

How can I force it to just input the JSON object and not inside the markdown string.

langchain~=0.2.6

crewai==0.36.0

mackimart1 commented 1 month ago

I've been having problems with my tools as well not sure why my search tool decided to stop working along with every other tool.

ChristianJohnston97 commented 1 month ago

@theCyberTech any thoughts? This is quite a big issue when using tools.