Skip to content

Commit

Permalink
Merge pull request #252 from ag2ai/interop-blog-polishing
Browse files Browse the repository at this point in the history
Interop blog polishing
  • Loading branch information
davorrunje authored Dec 20, 2024
2 parents 16515f3 + 5b62def commit 3c0b4e3
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 73 deletions.
42 changes: 29 additions & 13 deletions notebook/tools_interoperability.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"### Imports\n",
"\n",
"Import necessary modules and tools.\n",
"- `WikipediaQueryRun` and `WikipediaAPIWrapper`: Tools for querying Wikipedia.\n",
"\n",
"- [WikipediaQueryRun](https://api.python.langchain.com/en/latest/tools/langchain_community.tools.wikipedia.tool.WikipediaQueryRun.html) and [WikipediaAPIWrapper](https://python.langchain.com/api_reference/community/utilities/langchain_community.utilities.wikipedia.WikipediaAPIWrapper.html): Tools for querying Wikipedia.\n",
"- `AssistantAgent` and `UserProxyAgent`: Agents that facilitate communication in the AG2 framework.\n",
"- `Interoperability`: This module acts as a bridge, making it easier to integrate LangChain tools with AG2’s architecture."
]
Expand Down Expand Up @@ -76,6 +77,7 @@
"### Agent Configuration\n",
"\n",
"Configure the agents for the interaction.\n",
"\n",
"- `config_list` defines the LLM configurations, including the model and API key.\n",
"- `UserProxyAgent` simulates user inputs without requiring actual human interaction (set to `NEVER`).\n",
"- `AssistantAgent` represents the AI agent, configured with the LLM settings."
Expand Down Expand Up @@ -106,9 +108,9 @@
"### Tool Integration\n",
"\n",
"- Initialize and register the LangChain tool with AG2.\n",
"- `WikipediaAPIWrapper`: Configured to fetch the top 1 result from Wikipedia with a maximum of 1000 characters per document.\n",
"- `WikipediaQueryRun`: A LangChain tool that executes Wikipedia queries.\n",
"- `LangchainInteroperability`: Converts the LangChain tool into a format compatible with the AG2 framework.\n",
"- [WikipediaAPIWrapper](https://python.langchain.com/api_reference/community/utilities/langchain_community.utilities.wikipedia.WikipediaAPIWrapper.html): Configured to fetch the top 1 result from Wikipedia with a maximum of 1000 characters per document.\n",
"- [WikipediaQueryRun](https://api.python.langchain.com/en/latest/tools/langchain_community.tools.wikipedia.tool.WikipediaQueryRun.html): A LangChain tool that executes Wikipedia queries.\n",
"- `Interoperability`: Converts the LangChain tool into a format compatible with the AG2 framework.\n",
"- `ag2_tool.register_for_execution(user_proxy)`: Registers the tool for use by the user_proxy agent.\n",
"- `ag2_tool.register_for_llm(chatbot)`: Registers the tool for integration with the chatbot agent.\n"
]
Expand Down Expand Up @@ -215,7 +217,8 @@
"### Imports\n",
"\n",
"Import necessary modules and tools.\n",
"- `ScrapeWebsiteTool` are the CrewAI tools for web scraping\n",
"\n",
"- [ScrapeWebsiteTool](https://docs.crewai.com/tools/scrapewebsitetool) are the CrewAI tools for web scraping\n",
"- `AssistantAgent` and `UserProxyAgent` are core AG2 classes.\n",
"- `Interoperability`: This module acts as a bridge, making it easier to integrate CrewAI tools with AG2’s architecture."
]
Expand All @@ -241,6 +244,7 @@
"### Agent Configuration\n",
"\n",
"Configure the agents for the interaction.\n",
"\n",
"- `config_list` defines the LLM configurations, including the model and API key.\n",
"- `UserProxyAgent` simulates user inputs without requiring actual human interaction (set to `NEVER`).\n",
"- `AssistantAgent` represents the AI agent, configured with the LLM settings."
Expand Down Expand Up @@ -271,7 +275,8 @@
"### Tool Integration\n",
"\n",
"Initialize and register the CrewAI tool with AG2.\n",
"- `crewai_tool` is an instance of the `ScrapeWebsiteTool` from CrewAI.\n",
"\n",
"- `crewai_tool` is an instance of the [ScrapeWebsiteTool](https://docs.crewai.com/tools/scrapewebsitetool) from CrewAI.\n",
"- `Interoperability` converts the CrewAI tool to make it usable in AG2.\n",
"- `register_for_execution` and `register_for_llm` allow the tool to work with the UserProxyAgent and AssistantAgent."
]
Expand Down Expand Up @@ -413,12 +418,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Imports\n",
"### Imports\n",
"\n",
"Import necessary modules and tools.\n",
"- `BaseModel`: Used to define data structures for tool inputs and outputs.\n",
"- `RunContext`: Provides context during the execution of tools.\n",
"- `PydanticAITool`: Represents a tool in the PydanticAI framework.\n",
"\n",
"- [BaseModel](https://docs.pydantic.dev/latest/api/base_model/): Used to define data structures for tool inputs and outputs.\n",
"- [RunContext](https://ai.pydantic.dev/api/tools/#pydantic_ai.tools.RunContext): Provides context during the execution of tools.\n",
"- [PydanticAITool](https://ai.pydantic.dev/api/tools/#pydantic_ai.tools.Tool): Represents a tool in the PydanticAI framework.\n",
"- `AssistantAgent` and `UserProxyAgent`: Agents that facilitate communication in the AG2 framework.\n",
"- `Interoperability`: This module acts as a bridge, making it easier to integrate PydanticAI tools with AG2’s architecture."
]
Expand Down Expand Up @@ -447,6 +453,7 @@
"### Agent Configuration\n",
"\n",
"Configure the agents for the interaction.\n",
"\n",
"- `config_list` defines the LLM configurations, including the model and API key.\n",
"- `UserProxyAgent` simulates user inputs without requiring actual human interaction (set to `NEVER`).\n",
"- `AssistantAgent` represents the AI agent, configured with the LLM settings."
Expand Down Expand Up @@ -478,8 +485,8 @@
"\n",
"Integrate the PydanticAI tool with AG2.\n",
"\n",
"- Define a `Player` model using `BaseModel` to structure the input data.\n",
"- Use `RunContext` to securely inject dependencies (like the `Player` instance) into the tool function without exposing them to the LLM.\n",
"- Define a `Player` model using [BaseModel](https://docs.pydantic.dev/latest/api/base_model/) to structure the input data.\n",
"- Use [RunContext](https://ai.pydantic.dev/api/tools/#pydantic_ai.tools.RunContext) to securely inject dependencies (like the `Player` instance) into the tool function without exposing them to the LLM.\n",
"- Implement `get_player` to define the tool's functionality, accessing `ctx.deps` for injected data.\n",
"- Convert the tool to an AG2-compatible format with `Interoperability` and register it for execution and LLM communication.\n",
"- Convert the PydanticAI tool into an AG2-compatible format using `convert_tool`.\n",
Expand Down Expand Up @@ -525,7 +532,7 @@
"\n",
"- Use the `initiate_chat` method to send a message from the `user_proxy` to the `chatbot`.\n",
"- In this example, the user requests the chatbot to retrieve player information, providing \"goal keeper\" as additional context.\n",
"- The `Player` instance is securely injected into the tool using `RunContext`, ensuring the chatbot can retrieve and use this data during the interaction."
"- The `Player` instance is securely injected into the tool using [RunContext](https://ai.pydantic.dev/api/tools/#pydantic_ai.tools.RunContext), ensuring the chatbot can retrieve and use this data during the interaction."
]
},
{
Expand Down Expand Up @@ -595,6 +602,15 @@
}
],
"metadata": {
"front_matter": {
"description": "Cross-Framework LLM Tool Integration with AG2",
"tags": [
"tools",
"langchain",
"crewai",
"pydanticai"
]
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
Expand Down
Loading

0 comments on commit 3c0b4e3

Please sign in to comment.