mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
- Add ExecutionStep and ExecutionTrace models to track crew execution steps - Add ExecutionTraceCollector to capture events and build execution traces - Add trace_execution parameter to Crew class (disabled by default) - Add execution_trace field to CrewOutput to return trace data - Integrate trace collection into crew.kickoff() method - Add comprehensive tests covering execution tracing functionality - Add example demonstrating how to use execution tracing - Export new classes in __init__.py Addresses issue #3268: Users can now track the sequence of steps/actions that a crew takes to complete a goal, including agent thoughts, tool calls, and intermediate results, similar to LangGraph's conversation state. Co-Authored-By: João <joao@crewai.com>
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
from crewai import Agent, Crew, Task, Process, LLM
|
|
|
|
researcher = Agent(
|
|
role="Researcher",
|
|
goal="Research and analyze information",
|
|
backstory="You are an expert researcher with years of experience.",
|
|
llm=LLM(model="gpt-4o-mini")
|
|
)
|
|
|
|
writer = Agent(
|
|
role="Writer",
|
|
goal="Write compelling content",
|
|
backstory="You are a skilled writer who creates engaging content.",
|
|
llm=LLM(model="gpt-4o-mini")
|
|
)
|
|
|
|
research_task = Task(
|
|
description="Research the latest trends in AI",
|
|
expected_output="A comprehensive report on AI trends",
|
|
agent=researcher
|
|
)
|
|
|
|
writing_task = Task(
|
|
description="Write an article based on the research",
|
|
expected_output="A well-written article about AI trends",
|
|
agent=writer
|
|
)
|
|
|
|
crew = Crew(
|
|
agents=[researcher, writer],
|
|
tasks=[research_task, writing_task],
|
|
process=Process.sequential,
|
|
trace_execution=True
|
|
)
|
|
|
|
result = crew.kickoff(inputs={"topic": "artificial intelligence"})
|
|
|
|
if result.execution_trace:
|
|
print(f"Total execution steps: {result.execution_trace.total_steps}")
|
|
print(f"Execution duration: {result.execution_trace.end_time - result.execution_trace.start_time}")
|
|
|
|
thoughts = result.execution_trace.get_steps_by_type("agent_thought")
|
|
print(f"Agent thoughts captured: {len(thoughts)}")
|
|
|
|
tool_calls = result.execution_trace.get_steps_by_type("tool_call_started")
|
|
print(f"Tool calls made: {len(tool_calls)}")
|
|
|
|
for step in result.execution_trace.steps:
|
|
print(f"{step.timestamp}: {step.step_type} - {step.agent_role or 'System'}")
|