Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interop blog polishing #252

Merged
merged 13 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 All @@ -65,6 +66,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 @@ -95,9 +97,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 @@ -152,7 +154,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 @@ -178,6 +181,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 @@ -208,7 +212,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 @@ -260,12 +265,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 @@ -294,6 +300,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 @@ -325,8 +332,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 @@ -372,7 +379,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 All @@ -395,6 +402,15 @@
}
],
"metadata": {
"front_matter": {
"description": "Cross-Framework LLM Tool Integration with AG2",
"tags": [
"tools",
"langchain",
"crewai",
"pydanticai"
]
},
"kernelspec": {
"display_name": ".venv",
"language": "python",
Expand Down
Loading
Loading