Skip to content

Commit

Permalink
added autogen examples (#298)
Browse files Browse the repository at this point in the history
* added autogen examples

* added new docs card

* indexnt mdx

* updated notebooks or black

* remove black jupyter

* revert black
  • Loading branch information
areibman authored Jul 18, 2024
1 parent 801ac7d commit ece1049
Show file tree
Hide file tree
Showing 4 changed files with 547 additions and 3 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions docs/v1/examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ mode: "wide"
<Card title="Simple Agent" icon="person-carry-box" iconType="solid" href="https://github.com/AgentOps-AI/agentops-py/blob/main/examples/openai-gpt.ipynb">
Jupyter Notebook with sample code that you can run! Start here!
</Card>
<Card title="Crew.ai Example" icon="ship" href="/v1/integrations/crewai">
CrewAI multi-agent framework with AgentOps support
</Card>
<Card title="AutoGen" icon="microsoft" href="/v1/integrations/autogen">
AutoGen multi-agent conversible workflow with tool usage
</Card>
<Card title="Multi-Agent Code Example" icon="people-arrows" iconType="duotone" href="https://github.com/AgentOps-AI/agentops-py/blob/main/examples/multi_agent_example.ipynb">
Jupyter Notebook with a simple multi-agent design
</Card>
<Card title="LangChain Example" icon="link" href="https://github.com/AgentOps-AI/agentops-py/blob/main/examples/langchain_examples.ipynb">
Jupyter Notebook with a sample LangChain integration
</Card>
<Card title="Crew.ai Example" icon="ship" href="/v1/integrations/crewai">
CrewAI multi-agent framework with AgentOps support
</Card>
<Card title="FastAPI Example" icon="computer" href="/v1/examples/fastapi">
Create a REST server that performs and observes agent tasks
</Card>
Expand Down
219 changes: 219 additions & 0 deletions examples/autogen/AgentChat.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"id": "bb6538d8-2a5d-4a99-b2c1-7130963e4f7b",
"metadata": {},
"source": [
"# Adding AgentOps to an existing Autogen service\n",
"<img src=\"https://raw.githubusercontent.com/AgentOps-AI/agentops/main/docs/images/external/autogen/autogen_integration.png?raw=true\"/>\n",
"\n",
"To get started, you'll need to install the AgentOps package and [set an API key](app.agentops.ai).\n",
"\n",
"AgentOps automatically configures itself when it's initialized meaning your agent run data will be tracked and logged to your AgentOps account right away."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "d93f2339-7b99-4cf1-9232-c24faba49c7b",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"🖇 AgentOps: \u001b[34m\u001b[34mSession Replay: https://app.agentops.ai/drilldown?session_id=24c5d9f6-fb82-41e6-a468-2dc74a5318a3\u001b[0m\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AgentOps is now running. You can view your session in the link above\n"
]
}
],
"source": [
"import agentops\n",
"\n",
"from autogen import ConversableAgent, UserProxyAgent\n",
"\n",
"# When initializing AgentOps, you can pass in optional tags to help filter sessions\n",
"agentops.init(api_key=\"...\", tags=[\"simple-autogen-example\"])\n",
"\n",
"print(\"AgentOps is now running. You can view your session in the link above\")"
]
},
{
"cell_type": "markdown",
"id": "7858f0f6-9aca-4cdb-a514-9fbf7e353d50",
"metadata": {},
"source": [
"AutoGen will now start automatically tracking\n",
"\n",
"* LLM prompts and completions\n",
"* Token usage and costs\n",
"* Agent names and actions\n",
"* Correspondence between agents\n",
"* Tool usage\n",
"* Errors"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "2962d990-f7ef-43d8-ba09-d29bd8356d9f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33magent\u001b[0m (to user):\n",
"\n",
"How can I help you today?\n",
"\n",
"--------------------------------------------------------------------------------\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Provide feedback to agent. Press enter to skip and use auto-reply, or type 'exit' to end the conversation: Tell me a joke about AgentOps\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33muser\u001b[0m (to agent):\n",
"\n",
"Tell me a joke about AgentOps\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33magent\u001b[0m (to user):\n",
"\n",
"Why don't AgentOps teams ever play hide and seek?\n",
"\n",
"Because good luck hiding when they always know where everyone is supposed to be!\n",
"\n",
"--------------------------------------------------------------------------------\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Provide feedback to agent. Press enter to skip and use auto-reply, or type 'exit' to end the conversation: Another\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33muser\u001b[0m (to agent):\n",
"\n",
"Another\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33magent\u001b[0m (to user):\n",
"\n",
"Why did the AgentOps team bring a ladder to work?\n",
"\n",
"Because they’re always reaching for high-level optimizations!\n",
"\n",
"--------------------------------------------------------------------------------\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Provide feedback to agent. Press enter to skip and use auto-reply, or type 'exit' to end the conversation: exit\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"🖇 AgentOps: This run's cost $0.001080\n",
"🖇 AgentOps: \u001b[34m\u001b[34mSession Replay: https://app.agentops.ai/drilldown?session_id=24c5d9f6-fb82-41e6-a468-2dc74a5318a3\u001b[0m\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Success! Visit your AgentOps dashboard to see the replay\n"
]
}
],
"source": [
"# Define an openai api key for the agent configurations\n",
"openai_api_key = \"...\"\n",
"config_list = [\n",
" {\"model\": \"gpt-4-turbo\", \"api_key\": openai_api_key, \"tags\": [\"gpt-4\", \"tool\"]}\n",
"]\n",
"\n",
"# Create the agent that uses the LLM.\n",
"assistant = ConversableAgent(\"agent\", llm_config={\"config_list\": config_list})\n",
"\n",
"# Create the agent that represents the user in the conversation.\n",
"user_proxy = UserProxyAgent(\"user\", code_execution_config=False)\n",
"\n",
"# Let the assistant start the conversation. It will end when the user types \"exit\".\n",
"assistant.initiate_chat(user_proxy, message=\"How can I help you today?\")\n",
"\n",
"# Close your AgentOps session to indicate that it completed.\n",
"agentops.end_session(\"Success\")\n",
"print(\"Success! Visit your AgentOps dashboard to see the replay\")"
]
},
{
"cell_type": "markdown",
"id": "7b422137-903a-41ef-a4ca-95b50aea4138",
"metadata": {},
"source": [
"You can view data on this run at [app.agentops.ai](app.agentops.ai).\n",
"\n",
"The dashboard will display LLM events for each message sent by each agent, including those made by the human user."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "72993a75-1031-4874-aa26-0ef816a3256c",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit ece1049

Please sign in to comment.