Skip to main content

Connectors as Tools

View as Markdown

An 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:

OperationEffect classRuns in
QueryreadCallTool, with retries
Mutation that the manifest marks retry-safe (agent.retry: safe)idempotent_writeCallTool, with retries
Mutation with bounded resends (agent.repeatOnUnknown: limited)non_idempotent_writeCallSingleAttemptTool; after an unknown outcome it can resend within a send cap
Any other Mutationnon_idempotent_writeCallSingleAttemptTool, 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.

slack_connector_tools.pyPython
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

The Worker opens the connection once, at startup, and every agent uses it:

__main__.pyPython
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

The agent passes the tool source next to its own tools:

claude_agent_sdk_order_support.pyPython
    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

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