mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-01 07:13:00 +00:00
refactor: replace InstanceOf[T] with plain type annotations
InstanceOf[] is a Pydantic validation wrapper that adds runtime isinstance checks. Plain type annotations are sufficient here since the models already use arbitrary_types_allowed or the types are BaseModel subclasses.
This commit is contained in:
@@ -25,7 +25,6 @@ from pydantic import (
|
|||||||
BaseModel,
|
BaseModel,
|
||||||
ConfigDict,
|
ConfigDict,
|
||||||
Field,
|
Field,
|
||||||
InstanceOf,
|
|
||||||
PrivateAttr,
|
PrivateAttr,
|
||||||
model_validator,
|
model_validator,
|
||||||
)
|
)
|
||||||
@@ -167,10 +166,10 @@ class Agent(BaseAgent):
|
|||||||
default=True,
|
default=True,
|
||||||
description="Use system prompt for the agent.",
|
description="Use system prompt for the agent.",
|
||||||
)
|
)
|
||||||
llm: str | InstanceOf[BaseLLM] | None = Field(
|
llm: str | BaseLLM | None = Field(
|
||||||
description="Language model that will run the agent.", default=None
|
description="Language model that will run the agent.", default=None
|
||||||
)
|
)
|
||||||
function_calling_llm: str | InstanceOf[BaseLLM] | None = Field(
|
function_calling_llm: str | BaseLLM | None = Field(
|
||||||
description="Language model that will run the agent.", default=None
|
description="Language model that will run the agent.", default=None
|
||||||
)
|
)
|
||||||
system_template: str | None = Field(
|
system_template: str | None = Field(
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ from pydantic import (
|
|||||||
UUID4,
|
UUID4,
|
||||||
BaseModel,
|
BaseModel,
|
||||||
Field,
|
Field,
|
||||||
InstanceOf,
|
|
||||||
PrivateAttr,
|
PrivateAttr,
|
||||||
field_validator,
|
field_validator,
|
||||||
model_validator,
|
model_validator,
|
||||||
@@ -185,7 +184,7 @@ class BaseAgent(BaseModel, ABC, metaclass=AgentMeta):
|
|||||||
default=None,
|
default=None,
|
||||||
description="Knowledge sources for the agent.",
|
description="Knowledge sources for the agent.",
|
||||||
)
|
)
|
||||||
knowledge_storage: InstanceOf[BaseKnowledgeStorage] | None = Field(
|
knowledge_storage: BaseKnowledgeStorage | None = Field(
|
||||||
default=None,
|
default=None,
|
||||||
description="Custom knowledge storage for the agent.",
|
description="Custom knowledge storage for the agent.",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ from pydantic import (
|
|||||||
UUID4,
|
UUID4,
|
||||||
BaseModel,
|
BaseModel,
|
||||||
Field,
|
Field,
|
||||||
InstanceOf,
|
|
||||||
Json,
|
Json,
|
||||||
PrivateAttr,
|
PrivateAttr,
|
||||||
field_validator,
|
field_validator,
|
||||||
@@ -176,7 +175,7 @@ class Crew(FlowTrackable, BaseModel):
|
|||||||
_rpm_controller: RPMController = PrivateAttr()
|
_rpm_controller: RPMController = PrivateAttr()
|
||||||
_logger: Logger = PrivateAttr()
|
_logger: Logger = PrivateAttr()
|
||||||
_file_handler: FileHandler = PrivateAttr()
|
_file_handler: FileHandler = PrivateAttr()
|
||||||
_cache_handler: InstanceOf[CacheHandler] = PrivateAttr(default_factory=CacheHandler)
|
_cache_handler: CacheHandler = PrivateAttr(default_factory=CacheHandler)
|
||||||
_memory: Memory | MemoryScope | MemorySlice | None = PrivateAttr(default=None)
|
_memory: Memory | MemoryScope | MemorySlice | None = PrivateAttr(default=None)
|
||||||
_train: bool | None = PrivateAttr(default=False)
|
_train: bool | None = PrivateAttr(default=False)
|
||||||
_train_iteration: int | None = PrivateAttr()
|
_train_iteration: int | None = PrivateAttr()
|
||||||
@@ -210,13 +209,13 @@ class Crew(FlowTrackable, BaseModel):
|
|||||||
default=None,
|
default=None,
|
||||||
description="Metrics for the LLM usage during all tasks execution.",
|
description="Metrics for the LLM usage during all tasks execution.",
|
||||||
)
|
)
|
||||||
manager_llm: str | InstanceOf[BaseLLM] | None = Field(
|
manager_llm: str | BaseLLM | None = Field(
|
||||||
description="Language model that will run the agent.", default=None
|
description="Language model that will run the agent.", default=None
|
||||||
)
|
)
|
||||||
manager_agent: BaseAgent | None = Field(
|
manager_agent: BaseAgent | None = Field(
|
||||||
description="Custom agent that will be used as manager.", default=None
|
description="Custom agent that will be used as manager.", default=None
|
||||||
)
|
)
|
||||||
function_calling_llm: str | InstanceOf[LLM] | None = Field(
|
function_calling_llm: str | LLM | None = Field(
|
||||||
description="Language model that will run the agent.", default=None
|
description="Language model that will run the agent.", default=None
|
||||||
)
|
)
|
||||||
config: Json[dict[str, Any]] | dict[str, Any] | None = Field(default=None)
|
config: Json[dict[str, Any]] | dict[str, Any] | None = Field(default=None)
|
||||||
@@ -267,7 +266,7 @@ class Crew(FlowTrackable, BaseModel):
|
|||||||
default=False,
|
default=False,
|
||||||
description="Plan the crew execution and add the plan to the crew.",
|
description="Plan the crew execution and add the plan to the crew.",
|
||||||
)
|
)
|
||||||
planning_llm: str | InstanceOf[BaseLLM] | Any | None = Field(
|
planning_llm: str | BaseLLM | Any | None = Field(
|
||||||
default=None,
|
default=None,
|
||||||
description=(
|
description=(
|
||||||
"Language model that will run the AgentPlanner if planning is True."
|
"Language model that will run the AgentPlanner if planning is True."
|
||||||
@@ -288,7 +287,7 @@ class Crew(FlowTrackable, BaseModel):
|
|||||||
"knowledge object."
|
"knowledge object."
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
chat_llm: str | InstanceOf[BaseLLM] | Any | None = Field(
|
chat_llm: str | BaseLLM | Any | None = Field(
|
||||||
default=None,
|
default=None,
|
||||||
description="LLM used to handle chatting with the crew.",
|
description="LLM used to handle chatting with the crew.",
|
||||||
)
|
)
|
||||||
@@ -1800,7 +1799,7 @@ class Crew(FlowTrackable, BaseModel):
|
|||||||
def test(
|
def test(
|
||||||
self,
|
self,
|
||||||
n_iterations: int,
|
n_iterations: int,
|
||||||
eval_llm: str | InstanceOf[BaseLLM],
|
eval_llm: str | BaseLLM,
|
||||||
inputs: dict[str, Any] | None = None,
|
inputs: dict[str, Any] | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test and evaluate the Crew with the given inputs for n iterations.
|
"""Test and evaluate the Crew with the given inputs for n iterations.
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ from pydantic import (
|
|||||||
UUID4,
|
UUID4,
|
||||||
BaseModel,
|
BaseModel,
|
||||||
Field,
|
Field,
|
||||||
InstanceOf,
|
|
||||||
PrivateAttr,
|
PrivateAttr,
|
||||||
field_validator,
|
field_validator,
|
||||||
model_validator,
|
model_validator,
|
||||||
@@ -204,7 +203,7 @@ class LiteAgent(FlowTrackable, BaseModel):
|
|||||||
role: str = Field(description="Role of the agent")
|
role: str = Field(description="Role of the agent")
|
||||||
goal: str = Field(description="Goal of the agent")
|
goal: str = Field(description="Goal of the agent")
|
||||||
backstory: str = Field(description="Backstory of the agent")
|
backstory: str = Field(description="Backstory of the agent")
|
||||||
llm: str | InstanceOf[BaseLLM] | Any | None = Field(
|
llm: str | BaseLLM | Any | None = Field(
|
||||||
default=None, description="Language model that will run the agent"
|
default=None, description="Language model that will run the agent"
|
||||||
)
|
)
|
||||||
tools: list[BaseTool] = Field(
|
tools: list[BaseTool] = Field(
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from pydantic import BaseModel, Field, InstanceOf
|
from pydantic import BaseModel, Field
|
||||||
from rich.box import HEAVY_EDGE
|
from rich.box import HEAVY_EDGE
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
from rich.table import Table
|
from rich.table import Table
|
||||||
@@ -39,9 +39,9 @@ class CrewEvaluator:
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
crew: Crew,
|
crew: Crew,
|
||||||
eval_llm: InstanceOf[BaseLLM] | str | None = None,
|
eval_llm: BaseLLM | str | None = None,
|
||||||
openai_model_name: str | None = None,
|
openai_model_name: str | None = None,
|
||||||
llm: InstanceOf[BaseLLM] | str | None = None,
|
llm: BaseLLM | str | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.crew = crew
|
self.crew = crew
|
||||||
self.llm = eval_llm
|
self.llm = eval_llm
|
||||||
|
|||||||
Reference in New Issue
Block a user