Connectors as Tools
View as MarkdownAn agent can call official Connector operations as tools. Each call runs one operation in its own tool Step, with the Connector's credentials and the same stable Call ID that a Connector Step gets. A Mutation derives the idempotency key it sends to the provider from that Call ID, so every attempt of the call sends the same key.
How it works
ConnectorToolSource offers the operations you name. The agent takes it as a tool source: tool_sources in Python, toolSources in TypeScript, and the WithToolSources option in Go. Name the tools says which operations a manifest lets an agent use.
Dex checks the model's arguments against the operation's input schema first. A wrong or missing field fails the call before the operation runs, with a message the model can correct.
Effect classes
The operation's effect class becomes the tool's effect class, and so picks the Step that runs a call:
| Operation | Effect class | Runs in |
|---|---|---|
| Query | read | CallTool, with retries |
| Mutation that the manifest marks retry-safe (agent.retry: safe) | idempotent_write | CallTool, with retries |
| Mutation with bounded resends (agent.repeatOnUnknown: limited) | non_idempotent_write | CallSingleAttemptTool; after an unknown outcome it can resend within a send cap |
| Any other Mutation | non_idempotent_write | CallSingleAttemptTool, one attempt for the call |
Bounded resends suit a write where a rare duplicate is acceptable, such as a chat message or an email. A session's tool policy cannot change a Connector tool's effect class; see Step options.
Approval
A Connector tool waits for approval when its manifest recommends it (agent.approval: recommended), as for a refund. Other Mutations run directly by default. The application can override that per tool, or pass a predicate that decides per call from its arguments, such as refunds above a limit. A predicate that raises asks for approval. A session's tool policy wins over both; see Step options.
Outcomes
The operation's branch decides the tool call's record: succeeded, failed, or outcome_unknown when a write may have taken effect. Outcomes lists every branch. Reconcile outcome_unknown as for any tool.
After a Worker crash, a Connector call follows What runs again, and a new call can repeat its effect. A Mutation with bounded resends sends again only after an unknown outcome that read-back cannot settle, within a cap that counts every send. Crashes shows each case.
Write order
Connector writes of one model response run one at a time, in the model's order. Reads, and calls of other tools, run in parallel. A write that needs approval asks for it only when its turn comes.
When a write fails, ends outcome_unknown, or is rejected, the later Connector writes of that response are skipped. Each records failed with skipped set and an error that starts "the tool did not run, so it is safe to call again". The Claude Agent SDK refuses such a write inside its segment instead; see Connector tools: Framework adapters.
Connect a Connector
With the Slack connection support-slack configured, each example agent gets the tool slack_post_thread_reply, which runs the Slack operation postThreadReply to reply in a thread. Without that connection, the examples log one line and run without the tool. Every example sets requires_approval=True (requiresApproval: true in TypeScript, connectortools.WithRequiresApproval(true) in Go), so every post waits for a person and then runs in CallSingleAttemptTool. The Go example's Slack Connector release adds bounded resends; The Slack tool in the examples says what each example's post can repeat.
Offer the tool
Install the connectors extra of dex-agents and the Connector package, such as dex-connector-slack (commands). connector_tool turns the operation into a tool.
def build_slack_tool_sources(connection: slack.Connection | None) -> list[ToolSource]:
"""Returns the Slack tool source, or no source when Slack is not configured."""
if connection is None:
return []
return [
ConnectorToolSource([
# The manifest does not ask for approval; this agent asks before every post.
connector_tool(
connection.post_thread_reply(), connection.reference, requires_approval=True
),
]),
]
# ...
async def open_slack_project_connection(
environment: Mapping[str, str] = os.environ,
) -> SlackProjectConnection | None:
# ...
# An incomplete or invalid configuration raises here, so the Worker fails at startup.
try:
project = await load_from_environment(environment)
except FileNotFoundError:
_log_slack_not_set_up("the connector configuration file does not exist")
return None
# ...
try:
connection = slack.new_project_connection(project, SLACK_CONNECTION_NAME)
except BaseException:
await project.close()
raise
return SlackProjectConnection(project, connection)
Example: examples/python/agent-harnesses/agent_harness_examples/slack_connector_tools.py
Add the Slack Connector module, github.com/superdurable/dex-connectors-library/connectors/slack/go; the package connectortools is part of the Go core. connectortools.NewConnectorTool turns the operation's agent tool into a tool.
// NewSlackToolSources returns the Slack tool source, or no source when connection is nil.
//
// The source offers one tool, slack_post_thread_reply. Each call runs in its
// own tool Step with the Connector's Call ID, after a person approves it. It
// returns an error when the Connector's agent tools cannot be built.
func NewSlackToolSources(connection *slack.Connection) ([]dexagents.ToolSource, error) {
if connection == nil {
return nil, nil
}
agentTools, err := connection.AgentTools()
if err != nil {
return nil, err
}
tools := []*connectortools.ConnectorTool{}
for _, agentTool := range agentTools {
if agentTool.Metadata().ToolName != SlackPostThreadReplyToolName {
continue
}
// Every post waits for a person, whatever the manifest recommends.
tool, err := connectortools.NewConnectorTool(agentTool, connectortools.WithRequiresApproval(true))
if err != nil {
return nil, err
}
tools = append(tools, tool)
}
source, err := connectortools.NewConnectorToolSource(tools)
if err != nil {
return nil, err
}
return []dexagents.ToolSource{source}, nil
}
Example: examples/go/agent-harnesses/ordersupport/slack_connector_tools.go
Install @superdurable/connectors-sdk and the Connector package, such as @superdurable/connector-slack (commands). connectorTool turns the operation into a tool.
export async function openSlackConnectionFromProject(
environment: NodeJS.ProcessEnv = process.env,
): Promise<Connection | undefined> {
// ...
const project = await loadFromEnvironment(environment);
// ...
return newProjectConnection(project, slackConnectionName);
}
// ...
export function createSlackConnectorToolSources(slack: Connection | undefined): ToolSource[] {
if (slack === undefined) {
return [];
}
return [
new ConnectorToolSource([
connectorTool(slack.operations.postThreadReply(), slack.reference, {
manifest,
inputValidator: PostThreadReplyInputSchema,
// The manifest does not ask for approval; this agent asks before every post.
requiresApproval: true,
}),
]),
];
}
Example: examples/typescript/src/shared/slack-connector-tools.ts
The Worker opens the connection once, at startup, and every agent uses it:
async def main() -> None:
config = AgentHarnessExamplesConfig.from_env()
slack_setup = await open_slack_project_connection()
try:
app_state = AgentHarnessExamplesApp(config, slack_setup.connection if slack_setup else None)
# ...
finally:
if slack_setup is not None:
await slack_setup.aclose()
Example: examples/python/agent-harnesses/agent_harness_examples/__main__.py
// One Slack connection for the agent; without it the agent offers no Slack tool.
slackConnection, err := ordersupport.OpenSlackProjectConnection(ctx)
if err != nil {
return err
}
slackToolSources, err := ordersupport.NewSlackToolSources(slackConnection)
if err != nil {
return err
}
Example: examples/go/agent-harnesses/cmd/order-support/main.go
// One Slack connection for the agent examples; without it they offer no Slack tools.
const slack = await openSlackConnectionFromProject();
Example: examples/typescript/src/registry.ts
The agent passes the tool source next to its own tools:
- Claude Agent SDK
- Eino
- Google ADK
- LangGraph
- Mastra
- OpenAI Agents SDK
- Pi
- Pydantic AI
- Vercel AI SDK
- Dex Agent Framework
return claude_agent_session_flow(
build_options,
[look_up_order, cancel_order],
flow_type=CLAUDE_AGENT_SDK_ORDER_SUPPORT_FLOW_TYPE,
tool_sources=build_slack_tool_sources(slack_connection),
# ...
)
Example: examples/python/agent-harnesses/agent_harness_examples/claude_agent_sdk_order_support.py
return createClaudeAgentSessionFlow(
{
// ...
toolSources: createSlackConnectorToolSources(slack),
},
claudeAgentSdkOrderSupportFlowType,
);
return dexeino.NewAgentSessionFlow(config, EinoOrderSupportFlowType,
dexeino.WithToolEffects(map[string]dexagents.ToolEffect{
"look_up_order": dexagents.ToolEffectRead,
// Not safe to repeat, so Dex asks for approval first and runs it at most once.
"cancel_order": dexagents.ToolEffectNonIdempotentWrite,
}),
dexeino.WithToolSources(toolSources...))
Example: examples/go/agent-harnesses/ordersupport/eino_order_support.go
return adk_agent_session_flow(
agent,
flow_type=GOOGLE_ADK_ORDER_SUPPORT_FLOW_TYPE,
tool_sources=build_slack_tool_sources(slack_connection),
# ...
)
Example: examples/python/agent-harnesses/agent_harness_examples/google_adk_order_support.py
return langchain_agent_session_flow(
build_order_support_agent,
flow_type=LANGCHAIN_ORDER_SUPPORT_FLOW_TYPE,
tool_sources=build_slack_tool_sources(slack_connection),
# ...
)
Example: examples/python/agent-harnesses/agent_harness_examples/langchain_order_support.py
return createMastraAgentSessionFlow(agent, mastraOrderSupportFlowType, {
// ...
toolSources: createSlackConnectorToolSources(slack),
});
Example: examples/typescript/src/products/agent-harnesses/mastra/mastra-order-support-flow.ts
return openai_agents_session_flow(
agent,
flow_type=OPENAI_AGENTS_ORDER_SUPPORT_FLOW_TYPE,
tool_sources=build_slack_tool_sources(slack_connection),
# ...
)
Example: examples/python/agent-harnesses/agent_harness_examples/openai_agents_order_support.py
return createOpenAIAgentsSessionFlow(agent, openAIAgentsOrderSupportFlowType, {
// ...
toolSources: createSlackConnectorToolSources(slack),
});
Example: examples/typescript/src/products/agent-harnesses/openai-agents/openai-agents-order-support-flow.ts
return createBuiltinAgentSessionFlow(
{
// ...
toolSources: createSlackConnectorToolSources(slack),
},
piOrderSupportFlowType,
);
Example: examples/typescript/src/products/agent-harnesses/pi/pi-order-support-flow.ts
return pydantic_ai_session_flow(
agent,
flow_type=PYDANTIC_AI_ORDER_SUPPORT_FLOW_TYPE,
tool_sources=build_slack_tool_sources(slack_connection),
# ...
)
Example: examples/python/agent-harnesses/agent_harness_examples/pydantic_ai_order_support.py
return createVercelAiAgentSessionFlow(
{
// ...
toolSources: createSlackConnectorToolSources(slack),
},
vercelAiOrderSupportFlowType,
);
Example: examples/typescript/src/products/agent-harnesses/vercel-ai/vercel-ai-order-support-flow.ts
The Dex Agent Framework example installs the same packages as Offer the tool and has its own copy of the tool source module:
def build_slack_tool_sources(connection: slack.Connection | None) -> list[ToolSource]:
"""Returns the Slack tool source, or no source when Slack is not configured."""
if connection is None:
return []
return [
ConnectorToolSource([
# The manifest does not ask for approval; this agent asks before every post.
connector_tool(
connection.post_thread_reply(), connection.reference, requires_approval=True
),
]),
]
# ...
async def open_slack_project_connection(
environment: Mapping[str, str] = os.environ,
) -> SlackProjectConnection | None:
# ...
# An incomplete or invalid configuration raises here, so the Worker fails at startup.
try:
project = await load_from_environment(environment)
except FileNotFoundError:
_log_slack_not_set_up("the connector configuration file does not exist")
return None
# ...
try:
connection = slack.new_project_connection(project, SLACK_CONNECTION_NAME)
except BaseException:
await project.close()
raise
return SlackProjectConnection(project, connection)
Example: examples/python/dex_examples/products/ai-agent/slack_connector_tools.py
export async function openSlackConnectionFromProject(
environment: NodeJS.ProcessEnv = process.env,
): Promise<Connection | undefined> {
// ...
const project = await loadFromEnvironment(environment);
// ...
return newProjectConnection(project, slackConnectionName);
}
// ...
export function createSlackConnectorToolSources(slack: Connection | undefined): ToolSource[] {
if (slack === undefined) {
return [];
}
return [
new ConnectorToolSource([
connectorTool(slack.operations.postThreadReply(), slack.reference, {
manifest,
inputValidator: PostThreadReplyInputSchema,
// The manifest does not ask for approval; this agent asks before every post.
requiresApproval: true,
}),
]),
];
}
Example: examples/typescript/src/shared/slack-connector-tools.ts
The Worker opens the connection once, at startup, and every agent uses it:
async def main() -> None:
load_dotenv(Path(__file__).resolve().parents[1] / ".env")
config = ExamplesConfig.from_env()
slack_setup = await open_slack_project_connection()
try:
app_state = ExampleApp(config, slack_setup.connection if slack_setup else None)
# ...
finally:
if slack_setup is not None:
await slack_setup.aclose()
Example: examples/python/main.py
// One Slack connection for the agent examples; without it they offer no Slack tools.
const slack = await openSlackConnectionFromProject();
Example: examples/typescript/src/registry.ts
The agent takes the Slack tool source next to the MCP tool source:
mcp_tool_sources = (
[McpToolSource(mcp_servers, resource_and_prompt_tools_enabled=True)] if mcp_servers else []
)
definition = AgentDefinition(
# ...
tool_sources=[*mcp_tool_sources, *build_slack_tool_sources(slack_connection)],
# ...
)
Example: examples/python/dex_examples/products/ai-agent/ai_agent_session.py
// Each MCP tool's annotations pick its effect, and so whether it waits for approval.
toolSources: [
new McpToolSource(config.mcpServers, { resourceAndPromptToolsEnabled: true }),
...createSlackConnectorToolSources(slack),
],
Example: examples/typescript/src/products/ai-agent/ai-agent-flow.ts
Try the Slack tool
Start the example with DEX_CONNECTOR_CONFIG_FILE set; Connections says where the Worker finds support-slack. Then ask the agent to reply in a Slack thread, with the channel ID and the thread timestamp:
Reply in Slack thread C0123456789 1710000000.000100: Order 1002 ships on Thursday.
The post waits for approval, like cancel_order.
Next
- Dex Agent Framework: an agent without another agent SDK.
- Connector tools reference: packages, tool names, result size, connections, and how each agent SDK hands a call to its tool Step.
- Connector Triggers: start a session and send it messages from Connector events.