IBM WatsonX

Use IBM WatsonX foundation models with Kern agents.

IBM WatsonX provides access to powerful foundation models through IBM's cloud platform.

See all the IBM WatsonX supported models here.

  • We recommend using meta-llama/llama-3-3-70b-instruct for general use
  • We recommend ibm/granite-20b-code-instruct for code-related tasks
  • We recommend using meta-llama/llama-3-2-11b-vision-instruct for image understanding

Multimodal Support

With WatsonX we support Image as input

Authentication

Set your IBM_WATSONX_API_KEY and IBM_WATSONX_PROJECT_ID environment variables. Get your credentials from IBM Cloud. You can also set the IBM_WATSONX_URL environment variable to the URL of the WatsonX API you want to use. It defaults to https://eu-de.ml.cloud.ibm.com.

1export IBM_WATSONX_API_KEY=***
2export IBM_WATSONX_PROJECT_ID=***
1setx IBM_WATSONX_API_KEY ***
2setx IBM_WATSONX_PROJECT_ID ***

Example

Use WatsonX with your Agent:

1from kern.agent import Agent
2from kern.models.ibm import WatsonX
3
4agent = Agent(
5 model=WatsonX(id="meta-llama/llama-3-3-70b-instruct"),
6 markdown=True
7)
8
9# Print the response in the terminal
10agent.print_response("Share a 2 sentence horror story.")
Note View more examples here.

Params

ParameterTypeDefaultDescription
idstr"ibm/granite-13b-chat-v2"The id of the IBM watsonx model to use
namestr"IBMWatsonx"The name of the model
providerstr"IBMWatsonx"The provider of the model
api_keyOptional[str]NoneThe API key for IBM watsonx (defaults to WATSONX_API_KEY env var)
urlOptional[str]NoneThe URL for the IBM watsonx service
project_idOptional[str]NoneThe project ID for IBM watsonx
space_idOptional[str]NoneThe space ID for IBM watsonx
deployment_idOptional[str]NoneThe deployment ID for custom deployments
paramsOptional[Dict[str, Any]]NoneAdditional generation parameters (temperature, max_new_tokens, etc.)

WatsonX is a subclass of the Model class and has access to the same params.