Skip to content

Commit

Permalink
add company reseach and literature review examples with tools
Browse files Browse the repository at this point in the history
  • Loading branch information
victordibia committed Oct 8, 2024
1 parent 7a58cb4 commit 494b4db
Show file tree
Hide file tree
Showing 8 changed files with 1,034 additions and 95 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
myst:
html_meta:
"description lang=en": |
Examples built using AgentChat, a high-level api for AutoGen
---

# Examples

A list of examples to help you get started with AgentChat.

:::::{grid} 2 2 2 3

::::{grid-item-card} Travel Planning
:img-top: ../../images/code.svg
:img-alt: travel planning example
:link: ./travel-planning.html

^^^
Generating a travel plan using multiple agents.

::::

::::{grid-item-card} Company Research
:img-top: ../../images/code.svg
:img-alt: company research example
:link: ./company-research.html

^^^
Generating a company research report using multiple agents with tools.

::::

::::{grid-item-card} Literature Review
:img-top: ../../images/code.svg
:img-alt: literature review example
:link: ./literature-review.html

^^^
Generating a literature review using agents with tools.

::::

:::::

```{toctree}
:maxdepth: 1
:hidden:
travel-planning
company-research
literature-review
```

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -35,7 +35,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -58,7 +58,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand All @@ -67,31 +67,24 @@
"text": [
"\n",
"--------------------------------------------------------------------------- \n",
"\u001b[91m[2024-10-04T17:59:55.737430]:\u001b[0m\n",
"\u001b[91m[2024-10-08T09:50:13.202461]:\u001b[0m\n",
"\n",
"What's the weather in New York?\n",
"From: user"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"From: user\n",
"--------------------------------------------------------------------------- \n",
"\u001b[91m[2024-10-04T17:59:56.310787], Weather_Assistant:\u001b[0m\n",
"\u001b[91m[2024-10-08T09:50:14.090696], Weather_Assistant:\u001b[0m\n",
"\n",
"[FunctionCall(id='call_zxmdHPEQ1QMd2NwvYUSgxxDV', arguments='{\"city\":\"New York\"}', name='get_weather')]\n",
"[FunctionCall(id='call_wqkaIBdYjWklWG0GQkYz7FZ0', arguments='{\"city\":\"New York\"}', name='get_weather')]\n",
"From: Weather_Assistant\n",
"--------------------------------------------------------------------------- \n",
"\u001b[91m[2024-10-04T17:59:56.312084], tool_agent_for_Weather_Assistant:\u001b[0m\n",
"\u001b[91m[2024-10-08T09:50:14.092050], tool_agent_for_Weather_Assistant:\u001b[0m\n",
"\n",
"[FunctionExecutionResult(content='Sunny', call_id='call_zxmdHPEQ1QMd2NwvYUSgxxDV')]\n",
"[FunctionExecutionResult(content='The weather in New York is 72 degrees and Sunny.', call_id='call_wqkaIBdYjWklWG0GQkYz7FZ0')]\n",
"From: tool_agent_for_Weather_Assistant\n",
"--------------------------------------------------------------------------- \n",
"\u001b[91m[2024-10-04T17:59:56.767874], Weather_Assistant:\u001b[0m\n",
"\u001b[91m[2024-10-08T09:50:14.714470], Weather_Assistant:\u001b[0m\n",
"\n",
"The weather in New York is sunny. \n",
"The weather in New York is 72 degrees and sunny. \n",
"\n",
"TERMINATE\n",
"From: Weather_Assistant"
Expand Down Expand Up @@ -121,7 +114,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -139,37 +132,73 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--------------------------------------------------------------------------------\n",
"user:\n",
"Who was the first president of the United States?\n",
"--------------------------------------------------------------------------------\n",
"WikiPedia_Assistant:\n",
"[FunctionCall(id='call_CZA1pVGETEdvJv34aZ4dN7PF', arguments='{\"query\":\"first president of the United States\"}', name='wikipedia')]\n",
"--------------------------------------------------------------------------------\n",
"tool_agent:\n",
"[FunctionExecutionResult(content='Page: George Washington\\nSummary: George Washington (February 22, 1732 – December 14, 1799) was an Am', call_id='call_CZA1pVGETEdvJv34aZ4dN7PF')]\n",
"--------------------------------------------------------------------------------\n",
"WikiPedia_Assistant:\n",
"The first president of the United States was George Washington, who served from April 30, 1789, to March 4, 1797. \n",
"\n",
"TERMINATE\n"
"\n",
"--------------------------------------------------------------------------- \n",
"\u001b[91m[2024-10-08T09:51:36.869317]:\u001b[0m\n",
"\n",
"Who is the receipient of the 2023 Nobel Prize in Physics?\n",
"From: user"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"--------------------------------------------------------------------------- \n",
"\u001b[91m[2024-10-08T09:51:37.856066], WikiPedia_Assistant:\u001b[0m\n",
"\n",
"[FunctionCall(id='call_bdLqS1msbHCy5IMGYaata5vs', arguments='{\"query\":\"2023 Nobel Prize in Physics\"}', name='wikipedia')]\n",
"From: WikiPedia_Assistant\n",
"--------------------------------------------------------------------------- \n",
"\u001b[91m[2024-10-08T09:51:38.518288], tool_agent_for_WikiPedia_Assistant:\u001b[0m\n",
"\n",
"[FunctionExecutionResult(content='Page: Nobel Prize in Physics\\nSummary: The Nobel Prize in Physics (Swedish: Nobelpriset i fysik) is a', call_id='call_bdLqS1msbHCy5IMGYaata5vs')]\n",
"From: tool_agent_for_WikiPedia_Assistant\n",
"--------------------------------------------------------------------------- \n",
"\u001b[91m[2024-10-08T09:51:39.070911], WikiPedia_Assistant:\u001b[0m\n",
"\n",
"[FunctionCall(id='call_BFXGGeuBbOQ1LPb4f0NiNva2', arguments='{\"query\":\"2023 Nobel Prize in Physics recipients\"}', name='wikipedia')]\n",
"From: WikiPedia_Assistant\n",
"--------------------------------------------------------------------------- \n",
"\u001b[91m[2024-10-08T09:51:39.727147], tool_agent_for_WikiPedia_Assistant:\u001b[0m\n",
"\n",
"[FunctionExecutionResult(content='Page: Nobel Prize in Physics\\nSummary: The Nobel Prize in Physics (Swedish: Nobelpriset i fysik) is a', call_id='call_BFXGGeuBbOQ1LPb4f0NiNva2')]\n",
"From: tool_agent_for_WikiPedia_Assistant\n",
"--------------------------------------------------------------------------- \n",
"\u001b[91m[2024-10-08T09:51:40.746467], WikiPedia_Assistant:\u001b[0m\n",
"\n",
"[FunctionCall(id='call_iH2gkY5A2LiQTiy2eh86XpP5', arguments='{\"query\": \"2023 Nobel Prize in Physics winners\"}', name='wikipedia'), FunctionCall(id='call_rJXgJQiAKoD7yrymNJCsQA9N', arguments='{\"query\": \"Nobel Prize in Physics\"}', name='wikipedia')]\n",
"From: WikiPedia_Assistant\n",
"--------------------------------------------------------------------------- \n",
"\u001b[91m[2024-10-08T09:51:41.469348], tool_agent_for_WikiPedia_Assistant:\u001b[0m\n",
"\n",
"[FunctionExecutionResult(content='Page: Nobel Prize in Physics\\nSummary: The Nobel Prize in Physics (Swedish: Nobelpriset i fysik) is a', call_id='call_iH2gkY5A2LiQTiy2eh86XpP5'), FunctionExecutionResult(content='Page: Nobel Prize in Physics\\nSummary: The Nobel Prize in Physics (Swedish: Nobelpriset i fysik) is a', call_id='call_rJXgJQiAKoD7yrymNJCsQA9N')]\n",
"From: tool_agent_for_WikiPedia_Assistant\n",
"--------------------------------------------------------------------------- \n",
"\u001b[91m[2024-10-08T09:51:42.576718], WikiPedia_Assistant:\u001b[0m\n",
"\n",
"I couldn't find specific information about the recipients of the 2023 Nobel Prize in Physics. You might want to check a reliable news source or the official Nobel Prize website for the most accurate and up-to-date details. \n",
"\n",
"TERMINATE\n",
"From: WikiPedia_Assistant"
]
}
],
"source": [
"wikipedia_assistant = ToolUseAssistantAgent(\n",
" \"WikiPedia_Assistant\",\n",
" model_client=OpenAIChatCompletionClient(model=\"gpt-4o-mini\"),\n",
" tool_schema=[langchain_wikipedia_tool.schema],\n",
" registered_tools=[langchain_wikipedia_tool],\n",
")\n",
"team = RoundRobinGroupChat([wikipedia_assistant], tools=[langchain_wikipedia_tool])\n",
"team = RoundRobinGroupChat([wikipedia_assistant])\n",
"result = await team.run(\"Who was the first president of the United States?\")\n",
"\n",
"# print(result)"
Expand All @@ -185,7 +214,7 @@
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"display_name": "agnext",
"language": "python",
"name": "python3"
},
Expand All @@ -199,7 +228,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.6"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ myst:
html_meta:
"description lang=en": |
User Guide for AgentChat, a high-level api for AutoGen
User Guide for AgentChat, a high-level api for AutoGen
---

# AgentChat

AgentChat is a high-level package for building multi-agent applications built on top of the `autogen-core` package. For beginner users, AgentChat is the recommended starting point. For advanced users, `autogen-core` provides more flexibility and control over the underlying components.
AgentChat is a high-level package for building multi-agent applications built on top of the [ `autogen-core`](../core-user-guide/index.md) package. For beginner users, AgentChat is the recommended starting point. For advanced users, [ `autogen-core`](../core-user-guide/index.md) provides more flexibility and control over the underlying components.

AgentChat aims to provide intuitive defaults, such as **Agents** with preset behaviors and **Teams** with predefined communication protocols, to simplify building multi-agent applications.

```{tip}
If you are interested in implementing complex agent interaction behaviours, defining custom messaging protocols, or orchestration mechanisms, consider using the [ `autogen-core`](../core-user-guide/index.md) package.
```

## Agents

Agents provide presets for how an agent might respond to received messages. The following Agents are currently supported:
Expand All @@ -27,18 +33,18 @@ Teams define how groups of agents communicate to address tasks. The following Te

```{toctree}
:caption: Getting Started
:maxdepth: 1
:maxdepth: 2
:hidden:
quickstart
guides/tool_use
guides/examples
```

```{toctree}
:caption: Examples
:maxdepth: 1
:maxdepth: 3
:hidden:
examples/travel-planning
examples/index
```
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
myst:
html_meta:
"description lang=en": |
Quick Start Guide for AgentChat: Migrating from AutoGen 0.2x to 0.4x.
html_meta:
"description lang=en": |
Quick Start Guide for AgentChat: Migrating from AutoGen 0.2x to 0.4x.
---

# Quick Start

AgentChat API, introduced in AutoGen 0.4x, offers a similar level of abstraction as the default Agent classes in AutoGen 0.2x. This guide demonstrates how to migrate basic examples from AutoGen 0.2x to AgentChat in AutoGen 0.4x.
AgentChat API, introduced in AutoGen 0.4x, offers a similar level of abstraction as the default Agent classes in AutoGen 0.2x.

## Installation

Expand All @@ -22,62 +22,23 @@ pip install autogen-agentchat==0.4.0dev0
For further installation instructions, please refer to the [package information](pkg-info-autogen-agentchat).
:::

## Migrating from AutoGen 0.2x to 0.4x
## Creating a Simple Agent Team

The following example illustrates creating a simple agent team with two agents and compares how this is done in AutoGen 0.2x and 0.4x.
The following example illustrates creating a simple agent team with two agents that interact to solve a task.

1. An `AssistantAgent` (0.2x) / `CodingAssistantAgent` (0.4x) that generates responses using an LLM model.
2. A `UserProxyAgent` (0.2x) / `CodeExecutorAgent` (0.4x) that executes code snippets and returns the output.
1. `CodingAssistantAgent` that generates responses using an LLM model. 2.`CodeExecutorAgent` that executes code snippets and returns the output.

The task is to "Create a plot of NVIDIA and TESLA stock returns YTD from 2024-01-01 and save it to 'nvidia_tesla_2024_ytd.png'."

``````{tab-set}
`````{tab-item} AgentChat (v0.4x)
```python
from autogen_agentchat.agents import CodeExecutorAgent, CodingAssistantAgent
from autogen_agentchat.teams.group_chat import RoundRobinGroupChat
from autogen_core.components.code_executor import DockerCommandLineCodeExecutor
from autogen_core.components.models import OpenAIChatCompletionClient
async with DockerCommandLineCodeExecutor(work_dir="coding") as code_executor:
code_executor_agent = CodeExecutorAgent("code_executor", code_executor=code_executor)
coding_assistant_agent = CodingAssistantAgent(
"coding_assistant", model_client=OpenAIChatCompletionClient(model="gpt-4")
)
group_chat = RoundRobinGroupChat([coding_assistant_agent, code_executor_agent])
result = await group_chat.run(
task="Create a plot of NVIDIA and TESLA stock returns YTD from 2024-01-01 and save it to 'nvidia_tesla_2024_ytd.png'."
)
print(result)
```
`````
`````{tab-item} v0.2x
```python
from autogen import AssistantAgent, UserProxyAgent, config_list_from_json
config_list = config_list_from_json(env_or_file="OAI_CONFIG_LIST")
assistant = AssistantAgent("assistant", llm_config={"config_list": config_list})
code_executor_agent = UserProxyAgent(
"code_executor_agent",
code_execution_config={"work_dir": "coding", "use_docker": True}
)
code_executor_agent.initiate_chat(
assistant,
message="Create a plot of NVIDIA and TESLA stock returns YTD from 2024-01-01 and save it to 'nvidia_tesla_2024_ytd.png'."
)
```
`````
``````
```{include} stocksnippet.md
AgentChat in v0.4x provides similar abstractions to the default agents in v0.2x:
```

- `CodingAssistantAgent` (v0.4x) ~ `AssistantAgent` (v0.2x)
- `CodeExecutorAgent` (v0.4x) ~ `UserProxyAgent` with code execution (v0.2x)
```{tip}
AgentChat in v0.4x provides similar abstractions to the default agents in v0.2x. The `CodingAssistantAgent` and `CodeExecutorAgent` in v0.4x are equivalent to the `AssistantAgent` and `UserProxyAgent` with code execution in v0.2x.
```

Key differences:
If you are exploring migrating your code from AutoGen 0.2x to 0.4x, the following are some key differences to consider:

1. In v0.4x, agent interactions are managed by `Teams` (e.g., `RoundRobinGroupChat`), replacing direct chat initiation.
2. v0.4x uses async/await syntax for improved performance and scalability.
Expand Down
Loading

0 comments on commit 494b4db

Please sign in to comment.