feat: add agent refernece inside liteagent

This commit is contained in:
Eduardo Chiarotti
2025-04-10 15:57:57 -03:00
parent 5e4a8ca987
commit b0e63bd78e
3 changed files with 8 additions and 7 deletions

View File

@@ -482,6 +482,7 @@ class Agent(BaseAgent):
verbose=self.verbose,
response_format=response_format,
i18n=self.i18n,
original_agent=self,
)
return lite_agent.kickoff(messages)

View File

@@ -150,6 +150,10 @@ class LiteAgent(BaseModel):
default=[], description="Results of the tools used by the agent."
)
# Reference of Agent
original_agent: Optional[BaseAgent] = Field(
default=None, description="Reference to the agent that created this LiteAgent"
)
# Private Attributes
_parsed_tools: List[CrewStructuredTool] = PrivateAttr(default_factory=list)
_token_process: TokenProcess = PrivateAttr(default_factory=TokenProcess)
@@ -158,7 +162,7 @@ class LiteAgent(BaseModel):
_messages: List[Dict[str, str]] = PrivateAttr(default_factory=list)
_iterations: int = PrivateAttr(default=0)
_printer: Printer = PrivateAttr(default_factory=Printer)
@model_validator(mode="after")
def setup_llm(self):
"""Set up the LLM and other components after initialization."""
@@ -414,6 +418,7 @@ class LiteAgent(BaseModel):
i18n=self.i18n,
agent_key=self.key,
agent_role=self.role,
agent=self.original_agent,
)
except Exception as e:
raise e

View File

@@ -179,12 +179,7 @@ class ToolUsage:
if self.agent.fingerprint:
event_data.update(self.agent.fingerprint)
crewai_event_bus.emit(
self,
ToolUsageStartedEvent(
**event_data
),
)
crewai_event_bus.emit(self,ToolUsageStartedEvent(**event_data))
started_at = time.time()
from_cache = False