Defining a python tools expected credentials
When building Python tools that consume connections, you must explicitly define each expected connection in theexpected_credentials array within the @tool decorator.
If your Python file includes multiple tools, each tool must declare its own expected_credentials. This ensures that the tool can fetch the necessary connections during execution. Include all connections used directly within the tool function, as well as those used in any helper functions the tool calls.
If you attempt to import a tool with a connection type that doesn’t match one of the expected types for the specified app_id, the orchestrate tools import command will fail and prevent the tool from being imported.
PYTHON
Examples of fetching credentials per connection type
Here’s an example that shows how to look up connection credentials for each credential type:Basic Connections
Basic Connections
PYTHON
Bearer Connections
Bearer Connections
PYTHON
API Key Connections
API Key Connections
PYTHON
OAuth (Client Credentials)
OAuth (Client Credentials)
PYTHON
OAuth (Auth Code)
OAuth (Auth Code)
PYTHON
🚧 OAuth (Implicit)
🚧 OAuth (Implicit)
Coming soon
OAuth (Password)
OAuth (Password)
PYTHON
🌐OAuth (SSO/IDP Flow)
🌐OAuth (SSO/IDP Flow)
PYTHON
Key Value Connections
Key Value Connections
PYTHON
Combining multiple connection types for a single application id
You can define multiple authentication types for a singleapp_id, which is useful when using different methods in different environments—for example, basic authentication in draft mode and OAuth in production.
To support this, provide an array of credential types in the expected_credentials field instead of a single type. At runtime, your Python tool must determine which connection type to use by calling:
app_id, the orchestrate tools import command will fail and block the import.
PYTHON
Importing tools using connections
To import a Python tool that uses connections, use the-a app_id flag to bind each connection to the tool:
-a flag:
Additional functionality of python tools
Locally emulating python tool connections
When debugging Python tools outside watsonx Orchestrate, you can run them locally by emulating the environment variables that Orchestrate sets at runtime. These variables expose connection credentials to your tool, allowing you to test functionality without deploying the tool. Orchestrate uses the following naming convention to expose connections:Basic Connections
Basic Connections
BASH
Bearer Connections
Bearer Connections
BASH
API Key Connections
API Key Connections
BASH
OAuth (Client Credentials)
OAuth (Client Credentials)
BASH
OAuth (Auth Code)
OAuth (Auth Code)
BASH
🚧 OAuth (Implicit)
🚧 OAuth (Implicit)
Coming soon
OAuth (Password)
OAuth (Password)
BASH
🌐 OAuth (SSO/IDP Flow)
🌐 OAuth (SSO/IDP Flow)
BASH
Key Value Connections
Key Value Connections
BASH
Note:
The
app_id must be sanitized by replacing any character that is not alphanumeric (a-z, A-Z, 0-9) with an underscore (_).
