Plug-ins for agents
Plug-ins play a role in enhancing the capabilities and robustness of agents. They help enable custom behavior to be easily added to an agent’s processing flow, allowing modifications to incoming input or outgoing output. This customization is essential for applications where agents must comply with safety, security, and regulatory requirements. Plug-ins protect the agent from problematic inputs by filtering or sanitizing content and enforce compliance by applying guardrails to sensitive or restricted information. They also improve the reliability and trustworthiness of outputs by masking sensitive data or transforming results to meet specific standards.Input and output plug-ins overview
The agent workflow includes two types of plug-ins:- Input plug-ins - operate before the agent processes a request, inspecting and potentially modifying incoming messages.
- Output plug-ins - run after the agent generates a response, refining or changing the final output before it returns to the user.
kind=PythonToolKind.AGENTPREINVOKE for pre-invoke plug-ins or kind=PythonToolKind.AGENTPOSTINVOKE for post-invoke plug-ins.
For example, a pre-invoke plug-in is declared inline like this:
PYTHON
Implementation details
A plug-in receives two key pieces of information and must return a result when it finishes processing them:- Context – Contains details about the current state and user environment.
- Payload – Includes the data that is required for the plug-in to perform its task.
PluginContext, and AgentPostInvokePayload, can be imported from the ibm_watsonx_orchestrate library. The content, displayed as JSON for illustrative purposes, typically contains details about the current state and user environment, for example:
Collaborator access control
To check access to a collaborator agent, bind a pre-invoke plug-in to the collaborator agent.The plug-in is invoked during the parent agent pre-invoke execution. When checking collaborator access using a pre-invoke plug-in (
AgentPreInvokeType.RBAC_ONLY), if access to a specific collaborator agent is denied, that agent is removed from the parent agent’s list of collaborators.
Code example:
PYTHON
Within the plug-in, use the appropriate conditions to ensure access checks are performed only when necessary, avoiding repeated calls to the access-check API for the same thread.
agent_pre_invoke_payload, the messages list contains only one message, such as:
continue_processing = True or False. This mechanism helps enable the plug-in to accept, reject, or modify the agent’s workflow dynamically.
Email agent
Use this configuration to include an optional tool that the agent can call, such as a tool that simulates sending an email. Other plug-ins in this example run automatically, regardless of the agent’s actions. Code example:YAML
Email masking
The post-invoke plug-in masks email addresses after the agent completes its response. The plug-in runs automatically and modifies the final output before it is sent back to the user. The next utterance will use the updated context or conversation produced by the post-invoke plug-in processing of the previous utterance. Code example:PYTHON
Guardrail plug-in
The pre-invoke plug-in applies guardrails before the agent processes the request. It can strip or adjust content to enforce compliance or safety requirements. Code example:PYTHON
Import Python tools
Use this command to import Python-based tools for use as plug-ins. The tools can then be configured as pre-invoke or post-invoke plug-ins in the agent workflow. Command example:BASH
Import Python toolkits
You can configure Python toolkit tools as plugins. You define each tool individually in the plugins section of the configuration. To reference a specific tool, use the following format:YAML
orchestrate toolkits add or orchestrate toolkits import commands. For more information, see Add Python toolkits using the ADK CLI.
Command examples

