Examples
- Examples by Category
- Examples by Notebook
- Notebooks
- Using RetrieveChat Powered by MongoDB Atlas for Retrieve Augmented Code Generation and Question Answering
- Using RetrieveChat Powered by PGVector for Retrieve Augmented Code Generation and Question Answering
- Using RetrieveChat with Qdrant for Retrieve Augmented Code Generation and Question Answering
- Agent Tracking with AgentOps
- AgentOptimizer: An Agentic Way to Train Your LLM Agent
- Task Solving with Code Generation, Execution and Debugging
- Assistants with Azure Cognitive Search and Azure Identity
- CaptainAgent
- Usage tracking with AutoGen
- Agent Chat with custom model loading
- Agent Chat with Multimodal Models: DALLE and GPT-4V
- Use AutoGen in Databricks with DBRX
- Auto Generated Agent Chat: Task Solving with Provided Tools as Functions
- Task Solving with Provided Tools as Functions (Asynchronous Function Calls)
- Writing a software application using function calls
- Currency Calculator: Task Solving with Provided Tools as Functions
- Groupchat with Llamaindex agents
- Group Chat
- Group Chat with Retrieval Augmented Generation
- Group Chat with Customized Speaker Selection Method
- FSM - User can input speaker transition constraints
- Perform Research with Multi-Agent Group Chat
- StateFlow: Build Workflows through State-Oriented Actions
- Group Chat with Coder and Visualization Critic
- Using Guidance with AutoGen
- Auto Generated Agent Chat: Task Solving with Code Generation, Execution, Debugging & Human Feedback
- Generate Dalle Images With Conversable Agents
- Auto Generated Agent Chat: Function Inception
- Auto Generated Agent Chat: Task Solving with Langchain Provided Tools as Functions
- Engaging with Multimodal Models: GPT-4V in AutoGen
- Agent Chat with Multimodal Models: LLaVA
- Runtime Logging with AutoGen
- Agent with memory using Mem0
- Solving Multiple Tasks in a Sequence of Async Chats
- Solving Multiple Tasks in a Sequence of Chats
- Nested Chats for Tool Use in Conversational Chess
- Conversational Chess using non-OpenAI clients
- Solving Complex Tasks with A Sequence of Nested Chats
- Solving Complex Tasks with Nested Chats
- OptiGuide with Nested Chats in AutoGen
- Chat with OpenAI Assistant using function call in AutoGen: OSS Insights for Advanced GitHub Data Analysis
- Auto Generated Agent Chat: Group Chat with GPTAssistantAgent
- RAG OpenAI Assistants in AutoGen
- OpenAI Assistants in AutoGen
- Auto Generated Agent Chat: GPTAssistant with Code Interpreter
- Agent Observability with OpenLIT
- Auto Generated Agent Chat: Collaborative Task Solving with Coding and Planning Agent
- ReasoningAgent - Advanced LLM Reasoning with Multiple Search Strategies
- SocietyOfMindAgent
- SQL Agent for Spider text-to-SQL benchmark
- Interactive LLM Agent Dealing with Data Stream
- Structured output
- WebSurferAgent
- Swarm Orchestration with AG2
- Using a local Telemetry server to monitor a GraphRAG agent
- Trip planning with a FalkorDB GraphRAG agent using a Swarm
- (Legacy) Implement Swarm-style orchestration with GroupChat
- Chatting with a teachable agent
- Making OpenAI Assistants Teachable
- Auto Generated Agent Chat: Teaching AI New Skills via Natural Language Interaction
- Preprocessing Chat History with `TransformMessages`
- Auto Generated Agent Chat: Collaborative Task Solving with Multiple Agents and Human Users
- Translating Video audio using Whisper and GPT-3.5-turbo
- Auto Generated Agent Chat: Solving Tasks Requiring Web Info
- Web Scraping using Apify Tools
- Websockets: Streaming input and output using websockets
- Solving Multiple Tasks in a Sequence of Chats with Different Conversable Agent Pairs
- Demonstrating the `AgentEval` framework using the task of solving math problems as an example
- Agent Chat with Async Human Inputs
- Automatically Build Multi-agent System from Agent Library
- AutoBuild
- A Uniform interface to call different LLMs
- From Dad Jokes To Sad Jokes: Function Calling with GPTAssistantAgent
- Language Agent Tree Search
- Mitigating Prompt hacking with JSON Mode in Autogen
- Using RetrieveChat for Retrieve Augmented Code Generation and Question Answering
- Using Neo4j's graph database with AG2 agents for Question & Answering
- Enhanced Swarm Orchestration with AG2
- Cross-Framework LLM Tool Integration with AG2
- RealtimeAgent in a Swarm Orchestration
- ReasoningAgent - Advanced LLM Reasoning with Multiple Search Strategies
- Application Gallery
Chat with OpenAI Assistant using function call in AutoGen: OSS Insights for Advanced GitHub Data Analysis
This Jupyter Notebook demonstrates how to leverage OSS Insight (Open
Source Software Insight) for advanced GitHub data analysis by defining
Function calls
in AutoGen for the OpenAI Assistant.
The notebook is structured into four main sections:
- Function Schema and Implementation
- Defining an OpenAI Assistant Agent in AutoGen
- Fetching GitHub Insight Data using Function Call
Requirements
AutoGen requires Python>=3.9
. To run this notebook example, please
install:
:::info Requirements
Install `pyautogen`:
```bash
pip install pyautogen
```
For more information, please refer to the [installation guide](/docs/installation/).
:::
%%capture --no-stderr
# %pip install "pyautogen>=0.2.3"
Function Schema and Implementation
This section provides the function schema definition and their implementation details. These functions are tailored to fetch and process data from GitHub, utilizing OSS Insight’s capabilities.
import logging
import os
from autogen import UserProxyAgent, config_list_from_json
from autogen.agentchat.contrib.gpt_assistant_agent import GPTAssistantAgent
logger = logging.getLogger(__name__)
logger.setLevel(logging.WARNING)
ossinsight_api_schema = {
"name": "ossinsight_data_api",
"parameters": {
"type": "object",
"properties": {
"question": {
"type": "string",
"description": (
"Enter your GitHub data question in the form of a clear and specific question to ensure the returned data is accurate and valuable. "
"For optimal results, specify the desired format for the data table in your request."
),
}
},
"required": ["question"],
},
"description": "This is an API endpoint allowing users (analysts) to input question about GitHub in text format to retrieve the related and structured data.",
}
def get_ossinsight(question):
"""
[Mock] Retrieve the top 10 developers with the most followers on GitHub.
"""
report_components = [
f"Question: {question}",
"SQL: SELECT `login` AS `user_login`, `followers` AS `followers` FROM `github_users` ORDER BY `followers` DESC LIMIT 10",
"""Results:
{'followers': 166730, 'user_login': 'torvalds'}
{'followers': 86239, 'user_login': 'yyx990803'}
{'followers': 77611, 'user_login': 'gaearon'}
{'followers': 72668, 'user_login': 'ruanyf'}
{'followers': 65415, 'user_login': 'JakeWharton'}
{'followers': 60972, 'user_login': 'peng-zhihui'}
{'followers': 58172, 'user_login': 'bradtraversy'}
{'followers': 52143, 'user_login': 'gustavoguanabara'}
{'followers': 51542, 'user_login': 'sindresorhus'}
{'followers': 49621, 'user_login': 'tj'}""",
]
return "\n" + "\n\n".join(report_components) + "\n"
Defining an OpenAI Assistant Agent in AutoGen
Here, we explore how to define an OpenAI Assistant Agent within the AutoGen. This includes setting up the agent to make use of the previously defined function calls for data retrieval and analysis.
assistant_id = os.environ.get("ASSISTANT_ID", None)
config_list = config_list_from_json("OAI_CONFIG_LIST")
llm_config = {
"config_list": config_list,
}
assistant_config = {
"assistant_id": assistant_id,
"tools": [
{
"type": "function",
"function": ossinsight_api_schema,
}
],
}
oss_analyst = GPTAssistantAgent(
name="OSS Analyst",
instructions=(
"Hello, Open Source Project Analyst. You'll conduct comprehensive evaluations of open source projects or organizations on the GitHub platform, "
"analyzing project trajectories, contributor engagements, open source trends, and other vital parameters. "
"Please carefully read the context of the conversation to identify the current analysis question or problem that needs addressing."
),
llm_config=llm_config,
assistant_config=assistant_config,
verbose=True,
)
oss_analyst.register_function(
function_map={
"ossinsight_data_api": get_ossinsight,
}
)
OpenAI client config of GPTAssistantAgent(OSS Analyst) - model: gpt-4-turbo-preview
GPT Assistant only supports one OpenAI client. Using the first client in the list.
No matching assistant found, creating a new assistant
:::tip
Learn more about configuring LLMs for agents [here](/docs/topics/llm_configuration).
:::
Fetching GitHub Insight Data using Function Call
This part of the notebook demonstrates the practical application of the defined functions and the OpenAI Assistant Agent in fetching and interpreting GitHub Insight data.
user_proxy = UserProxyAgent(
name="user_proxy",
code_execution_config={
"work_dir": "coding",
"use_docker": False,
}, # Please set use_docker=True if docker is available to run the generated code. Using docker is safer than running the generated code directly.
is_termination_msg=lambda msg: "TERMINATE" in msg["content"],
human_input_mode="NEVER",
max_consecutive_auto_reply=1,
)
user_proxy.initiate_chat(oss_analyst, message="Top 10 developers with the most followers")
oss_analyst.delete_assistant()
user_proxy (to OSS Analyst):
Top 10 developers with the most followers
--------------------------------------------------------------------------------
>>>>>>>> EXECUTING FUNCTION ossinsight_data_api...
Input arguments: {'question': 'Top 10 developers with the most followers'}
Output:
Question: Top 10 developers with the most followers
SQL: SELECT `login` AS `user_login`, `followers` AS `followers` FROM `github_users` ORDER BY `followers` DESC LIMIT 10
Results:
{'followers': 166730, 'user_login': 'torvalds'}
{'followers': 86239, 'user_login': 'yyx990803'}
{'followers': 77611, 'user_login': 'gaearon'}
{'followers': 72668, 'user_login': 'ruanyf'}
{'followers': 65415, 'user_login': 'JakeWharton'}
{'followers': 60972, 'user_login': 'peng-zhihui'}
{'followers': 58172, 'user_login': 'bradtraversy'}
{'followers': 52143, 'user_login': 'gustavoguanabara'}
{'followers': 51542, 'user_login': 'sindresorhus'}
{'followers': 49621, 'user_login': 'tj'}
OSS Analyst (to user_proxy):
The top 10 developers with the most followers on GitHub are:
1. **Linus Torvalds** (`torvalds`) with 166,730 followers
2. **Evan You** (`yyx990803`) with 86,239 followers
3. **Dan Abramov** (`gaearon`) with 77,611 followers
4. **Ruan YiFeng** (`ruanyf`) with 72,668 followers
5. **Jake Wharton** (`JakeWharton`) with 65,415 followers
6. **Peng Zhihui** (`peng-zhihui`) with 60,972 followers
7. **Brad Traversy** (`bradtraversy`) with 58,172 followers
8. **Gustavo Guanabara** (`gustavoguanabara`) with 52,143 followers
9. **Sindre Sorhus** (`sindresorhus`) with 51,542 followers
10. **TJ Holowaychuk** (`tj`) with 49,621 followers
--------------------------------------------------------------------------------
user_proxy (to OSS Analyst):
--------------------------------------------------------------------------------
OSS Analyst (to user_proxy):
It looks like there is no question or prompt for me to respond to. Could you please provide more details or ask a question that you would like assistance with?
--------------------------------------------------------------------------------
Permanently deleting assistant...