Skip to content

Commit f8882dd

Browse files
committed
Merge branch 'v1.1' of github.com:raga-ai-hub/agentneo into v1.1
2 parents 0e41a03 + 4d41bf3 commit f8882dd

File tree

3 files changed

+1202
-0
lines changed

3 files changed

+1202
-0
lines changed
Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"\n",
8+
"# CrewAI with AgentNeo Integration\n",
9+
"This Jupyter notebook demonstrates the integration of AgentNeo, a powerful tracing and monitoring tool, with CrewAI, a framework for orchestrating role-playing AI agents. This integration allows for comprehensive analysis and debugging of AI-powered systems."
10+
]
11+
},
12+
{
13+
"cell_type": "markdown",
14+
"metadata": {},
15+
"source": [
16+
"# Setup and Imports\n",
17+
"First, let's import the necessary libraries and set up our environment."
18+
]
19+
},
20+
{
21+
"cell_type": "code",
22+
"execution_count": null,
23+
"metadata": {},
24+
"outputs": [],
25+
"source": [
26+
"from crewai import Agent, Task, Crew, Process\n",
27+
"from dotenv import load_dotenv\n",
28+
"\n",
29+
"from agentneo import AgentNeo, Tracer, Execution ,Evaluation, launch_dashboard\n",
30+
"\n",
31+
"# Load environment variables\n",
32+
"load_dotenv(\"enter your .env path\")"
33+
]
34+
},
35+
{
36+
"cell_type": "markdown",
37+
"metadata": {},
38+
"source": [
39+
"\n",
40+
"# Initialize AgentNeo Session and Tracer\n",
41+
"Now, let's set up our AgentNeo session and tracer."
42+
]
43+
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": null,
47+
"metadata": {},
48+
"outputs": [],
49+
"source": [
50+
"# Initialize AgentNeo Session and Tracer\n",
51+
"neo_session = AgentNeo(session_name=\"digital_marketing_campaign\")\n",
52+
"\n",
53+
"# Connect to a Project\n",
54+
"neo_session.create_project(project_name=\"digital_marketing_project\")\n",
55+
"\n",
56+
"# Create tracer\n",
57+
"tracer = Tracer(session=neo_session)\n",
58+
"\n",
59+
"tracer.start()"
60+
]
61+
},
62+
{
63+
"cell_type": "markdown",
64+
"metadata": {},
65+
"source": [
66+
"\n",
67+
"# Define Helper Functions\n",
68+
"Let's define some helper functions for our AI tools, using AgentNeo's tracing capabilities."
69+
]
70+
},
71+
{
72+
"cell_type": "code",
73+
"execution_count": 7,
74+
"metadata": {},
75+
"outputs": [],
76+
"source": [
77+
"from langchain_community.tools import TavilySearchResults\n",
78+
"\n",
79+
"seo_tool = tracer.wrap_langchain_tool(TavilySearchResults())"
80+
]
81+
},
82+
{
83+
"cell_type": "markdown",
84+
"metadata": {},
85+
"source": [
86+
"# Define Agents\n",
87+
"Now, let's create our AI agents using CrewAI."
88+
]
89+
},
90+
{
91+
"cell_type": "code",
92+
"execution_count": null,
93+
"metadata": {},
94+
"outputs": [],
95+
"source": [
96+
"# Define Agents\n",
97+
"@tracer.trace_agent(\"content_creator\")\n",
98+
"def create_content_creator():\n",
99+
" return Agent(\n",
100+
" role='Content Creator',\n",
101+
" goal='Produce engaging content for blogs and social media.',\n",
102+
" backstory=\"\"\"You are a skilled content creator specializing in crafting compelling narratives.\n",
103+
" Your content drives user engagement and brand awareness.\"\"\",\n",
104+
" verbose=True,\n",
105+
" allow_delegation=False,\n",
106+
" tools=[content_tool],\n",
107+
" )\n",
108+
"\n",
109+
"@tracer.trace_agent(\"social_media_manager\")\n",
110+
"def create_social_media_manager():\n",
111+
" return Agent(\n",
112+
" role='Social Media Manager',\n",
113+
" goal='Develop and execute a social media strategy to enhance brand presence.',\n",
114+
" backstory=\"\"\"As a social media manager, you excel at building brand communities and engaging audiences.\n",
115+
" You utilize analytics to inform your strategies.\"\"\",\n",
116+
" verbose=True,\n",
117+
" allow_delegation=True,\n",
118+
" tools=[social_media_tool],\n",
119+
" )\n",
120+
"\n",
121+
"@tracer.trace_agent(\"analytics_expert\")\n",
122+
"def create_analytics_expert():\n",
123+
" return Agent(\n",
124+
" role='Analytics Expert',\n",
125+
" goal='Analyze campaign performance and optimize strategies based on data.',\n",
126+
" backstory=\"\"\"You are an analytics expert with a knack for interpreting data.\n",
127+
" You provide actionable insights that drive marketing decisions.\"\"\",\n",
128+
" verbose=True,\n",
129+
" allow_delegation=True,\n",
130+
" tools=[analytics_tool],\n",
131+
" )\n",
132+
"\n",
133+
"content_creator = create_content_creator()\n",
134+
"social_media_manager = create_social_media_manager()\n",
135+
"analytics_expert = create_analytics_expert()\n",
136+
"\n"
137+
]
138+
},
139+
{
140+
"cell_type": "markdown",
141+
"metadata": {},
142+
"source": [
143+
"# Define Tasks\n",
144+
"Let's create tasks for our agents."
145+
]
146+
},
147+
{
148+
"cell_type": "code",
149+
"execution_count": 18,
150+
"metadata": {},
151+
"outputs": [],
152+
"source": [
153+
"# Define Tasks\n",
154+
"task1 = Task(\n",
155+
" description=\"\"\"Create a series of blog posts that highlight the features and benefits of the new product.\n",
156+
" Ensure SEO optimization for key search terms.\"\"\",\n",
157+
" expected_output=\"A set of blog posts in markdown format\",\n",
158+
" agent=content_creator\n",
159+
")\n",
160+
"\n",
161+
"task2 = Task(\n",
162+
" description=\"\"\"Develop a comprehensive social media strategy for the product launch,\n",
163+
" including content calendar and engagement tactics.\"\"\",\n",
164+
" expected_output=\"Social media strategy document\",\n",
165+
" agent=social_media_manager\n",
166+
")\n",
167+
"\n",
168+
"task3 = Task(\n",
169+
" description=\"\"\"Analyze the initial performance metrics of the marketing campaign,\n",
170+
" providing insights and recommendations for adjustments.\"\"\",\n",
171+
" expected_output=\"Analysis report with recommendations\",\n",
172+
" agent=analytics_expert\n",
173+
")"
174+
]
175+
},
176+
{
177+
"cell_type": "markdown",
178+
"metadata": {},
179+
"source": [
180+
"\n",
181+
"# Create and Execute Crew\n",
182+
"Now, let's create our crew and execute the tasks."
183+
]
184+
},
185+
{
186+
"cell_type": "code",
187+
"execution_count": null,
188+
"metadata": {},
189+
"outputs": [],
190+
"source": [
191+
"# Create and Execute Crew\n",
192+
"crew = Crew(\n",
193+
" agents=[content_creator, social_media_manager, analytics_expert],\n",
194+
" tasks=[task1, task2, task3],\n",
195+
" process=Process.sequential,\n",
196+
" verbose=True,\n",
197+
")\n",
198+
"result = crew.kickoff()\n",
199+
"\n",
200+
"print(result)\n",
201+
"tracer.stop()"
202+
]
203+
},
204+
{
205+
"cell_type": "markdown",
206+
"metadata": {},
207+
"source": [
208+
"# Metrics Evaluation\n",
209+
"Supported Metrics\n",
210+
"Goal Decomposition Efficiency (goal_decomposition_efficiency)\n",
211+
"Goal Fulfillment Rate (goal_fulfillment_rate)\n",
212+
"Tool Correctness Metric (tool_correctness_metric)\n",
213+
"Tool Call Success Rate Metric (tool_call_success_rate_metric)"
214+
]
215+
},
216+
{
217+
"cell_type": "code",
218+
"execution_count": 15,
219+
"metadata": {},
220+
"outputs": [],
221+
"source": [
222+
"exe = Execution(session=neo_session, trace_id=1)\n",
223+
"\n",
224+
"# run a single metric\n",
225+
"exe.execute(metric_list=['tool_call_success_rate_metric'])"
226+
]
227+
},
228+
{
229+
"cell_type": "code",
230+
"execution_count": null,
231+
"metadata": {},
232+
"outputs": [],
233+
"source": [
234+
"#print metric result\n",
235+
"metric_results = exe.get_results()\n",
236+
"print(metric_results)"
237+
]
238+
},
239+
{
240+
"cell_type": "code",
241+
"execution_count": null,
242+
"metadata": {},
243+
"outputs": [],
244+
"source": [
245+
"neo_session.launch_dashboard(port=3000)"
246+
]
247+
}
248+
],
249+
"metadata": {
250+
"kernelspec": {
251+
"display_name": "Python 3",
252+
"language": "python",
253+
"name": "python3"
254+
},
255+
"language_info": {
256+
"codemirror_mode": {
257+
"name": "ipython",
258+
"version": 3
259+
},
260+
"file_extension": ".py",
261+
"mimetype": "text/x-python",
262+
"name": "python",
263+
"nbconvert_exporter": "python",
264+
"pygments_lexer": "ipython3",
265+
"version": "3.11.10"
266+
}
267+
},
268+
"nbformat": 4,
269+
"nbformat_minor": 2
270+
}

0 commit comments

Comments
 (0)