This is an autogen>=0.4 extension for watsonx client integration.
Project description
autogen-watsonx-client
This is an autogen>=0.4 extension for watsonx client integration.
Disclaimer
- This is a community extension for the Autogen project, specifically for the new Autogen >= 0.4 architecture. The goal is to support IBM Watsonx.ai hosted LLMs in the Autogen framework.
- This project is still in a very early stage under development, please create issues in this github repo for bug reports.
- This project is a personal endeavor and is not affiliated with, endorsed by, or connected to any organization/employer in any way. The views, ideas, and opinions expressed in this project are solely my own and do not reflect those of others.
Announcements
- 2025-02-13:
create_streamis now implemented! - 2025-01-13: the version requirement on Autogen has been updated to
>=0.4.1, the integration examples have been updated accordingly, see here.
Usage
Prerequisites
- create a python environment with version
3.10or above pip install --upgrade autogen-watsonx-clientpip install --upgrade autogen-agentchat>=0.4.1- access to a watsonx.ai instance, setting up environment variables
WATSONX_API_KEY, one ofWATSONX_SPACE_IDorWATSONX_PROJECT_ID, optionallyWATSONX_URL
code snippets
Importing dependencies:
import os
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.ui import Console
from autogen_agentchat.conditions import TextMentionTermination
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_watsonx_client.config import WatsonxClientConfiguration
from autogen_watsonx_client.client import WatsonXChatCompletionClient
Create a watsonx client
wx_config = WatsonxClientConfiguration(
model_id="meta-llama/llama-3-2-90b-vision-instruct", # pick a model you have access to on wx.ai here
api_key=os.environ.get("WATSONX_API_KEY"),
url=os.environ.get("WATSONX_URL"),
space_id=os.environ.get("WATSONX_SPACE_ID"),
project_id=os.environ.get("WATSONX_PROJECT_ID"),
)
wx_client = WatsonXChatCompletionClient(**wx_config)
Define an agent using the watsonx client and register a dummy tool for querying weather
# Define a tool
async def get_weather(city: str) -> str:
return f"The weather in {city} is 73 degrees and Sunny."
async def main() -> None:
# Define an agent
weather_agent = AssistantAgent(
name="weather_agent",
model_client=wx_client,
tools=[get_weather],
)
# Define termination condition
termination = TextMentionTermination("TERMINATE")
# Define a team
agent_team = RoundRobinGroupChat([weather_agent], termination_condition=termination)
# Run the team and stream messages to the console
stream = agent_team.run_stream(task="What is the weather in New York?")
await Console(stream)
# NOTE: if running this inside a Python script you'll need to use asyncio.run(main()).
await main()
Refer to here for more detailed examples.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file autogen_watsonx_client-0.0.8.tar.gz.
File metadata
- Download URL: autogen_watsonx_client-0.0.8.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8962205347f86827da02030e759b6f987e5dea14fc46485b6462bb9dae11b5e8
|
|
| MD5 |
b296050319a89d81822974c69bb576ac
|
|
| BLAKE2b-256 |
9103826225721e357208818da57709e69c48f64c94fe7f0433adb28e0f80ae09
|
File details
Details for the file autogen_watsonx_client-0.0.8-py3-none-any.whl.
File metadata
- Download URL: autogen_watsonx_client-0.0.8-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cc9139341988562530ec07a9804354d23a048af0e49ff8caaa39fdbd11dff99
|
|
| MD5 |
9108e2707d138abd0f036952b935f7b4
|
|
| BLAKE2b-256 |
cdd43ec0e9b0bde4821a4098d37d89cf22a34a84850e44b26fa3a307db8696ff
|