Chris Johnston
Chris Johnston

Reputation: 361

CrewAI Langchain StructuredTool JSON

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>",
     ...
   }
```

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

langchain~=0.2.6

crewai==0.36.0

Upvotes: 0

Views: 262

Answers (0)

Related Questions