mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-07-05 23:19:22 +00:00
fix(tools): avoid Tavily output schema field conflict
This commit is contained in:
@@ -63,11 +63,12 @@ print(crew.kickoff())
|
||||
|
||||
## Configuration Options
|
||||
|
||||
The `TavilyResearchTool` accepts the following arguments — all can be set on the tool instance (defaults for every call) or per-call via the agent's tool input:
|
||||
The `TavilyResearchTool` accepts the following arguments. Set `model`, `tavily_output_schema`, `stream`, and `citation_format` on the tool instance as defaults; pass `input`, `model`, `output_schema`, `stream`, and `citation_format` per call via the agent's tool input:
|
||||
|
||||
- `input` (str): **Required.** The research task or question to investigate.
|
||||
- `model` (Literal["mini", "pro", "auto"]): The Tavily research model. `"auto"` lets Tavily pick; `"mini"` is faster/cheaper; `"pro"` is the most capable. Defaults to `"auto"`.
|
||||
- `output_schema` (dict | None): Optional JSON Schema that structures the research output. Useful when you want strictly typed results.
|
||||
- `output_schema` (dict | None): Optional per-call JSON Schema that structures the research output. Useful when you want strictly typed results.
|
||||
- `tavily_output_schema` (dict | None): Optional default JSON Schema for Tavily research output when the tool is instantiated.
|
||||
- `stream` (bool): When `True`, the tool returns an iterator of SSE chunks emitting research progress and the final result instead of a single string. Defaults to `False`.
|
||||
- `citation_format` (Literal["numbered", "mla", "apa", "chicago"]): Citation format for the report. Defaults to `"numbered"`.
|
||||
|
||||
@@ -97,7 +98,7 @@ for chunk in tavily_tool.run(input="Summarize recent advances in retrieval-augme
|
||||
|
||||
### Structured output via JSON Schema
|
||||
|
||||
Pass an `output_schema` when you need a typed result instead of a free-form report:
|
||||
Pass an `output_schema` per call, or set `tavily_output_schema` on the tool instance, when you need a typed result instead of a free-form report:
|
||||
|
||||
```python
|
||||
output_schema = {
|
||||
@@ -110,7 +111,7 @@ output_schema = {
|
||||
"required": ["summary", "key_points", "sources"],
|
||||
}
|
||||
|
||||
tavily_tool = TavilyResearchTool(output_schema=output_schema)
|
||||
tavily_tool = TavilyResearchTool(tavily_output_schema=output_schema)
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
@@ -63,7 +63,7 @@ class TavilyResearchTool(BaseTool):
|
||||
default="auto",
|
||||
description="Default model used for new Tavily research tasks.",
|
||||
)
|
||||
output_schema: dict[str, Any] | None = Field(
|
||||
tavily_output_schema: dict[str, Any] | None = Field(
|
||||
default=None,
|
||||
description="Default JSON Schema used to structure research output.",
|
||||
)
|
||||
@@ -87,6 +87,10 @@ class TavilyResearchTool(BaseTool):
|
||||
)
|
||||
|
||||
def __init__(self, **kwargs: Any):
|
||||
output_schema = kwargs.get("output_schema")
|
||||
if isinstance(output_schema, dict) and "tavily_output_schema" not in kwargs:
|
||||
kwargs["tavily_output_schema"] = kwargs.pop("output_schema")
|
||||
|
||||
super().__init__(**kwargs)
|
||||
if TAVILY_AVAILABLE:
|
||||
api_key = os.getenv("TAVILY_API_KEY")
|
||||
@@ -152,7 +156,7 @@ class TavilyResearchTool(BaseTool):
|
||||
result = self._client.research(
|
||||
input=input,
|
||||
model=self.model if model is None else model,
|
||||
output_schema=self.output_schema
|
||||
output_schema=self.tavily_output_schema
|
||||
if output_schema is None
|
||||
else output_schema,
|
||||
stream=use_stream,
|
||||
@@ -185,7 +189,7 @@ class TavilyResearchTool(BaseTool):
|
||||
result = await self._async_client.research(
|
||||
input=input,
|
||||
model=self.model if model is None else model,
|
||||
output_schema=self.output_schema
|
||||
output_schema=self.tavily_output_schema
|
||||
if output_schema is None
|
||||
else output_schema,
|
||||
stream=use_stream,
|
||||
|
||||
Reference in New Issue
Block a user