Interception
Interceptors allow you to plug custom logic into a channel connection at the ADK level to process and transform messages flowing through channels in real-time. Interceptors act as programmable filters in the message pipeline, enabling custom business logic, validation, transformation, and integration with external systems.
We suggest you understand the core concepts of Interceptor before diving into this section. To learn more about interceptors, click here
How to intercept
Interceptors can be integrated into the message pipeline at any required place using the orchestrator. While creating a channel, if the Enable Orchestrator option is checked, the flow of the message through the pipeline is decided by the orchestrator, which creates a flow chart of operations as nodes.
A channel can only be intercepted if the orchestrator is enabled at creation. It cannot be changed later.
You can learn more about Message orchestration and configuring the orchestrator from the Agent Builder Documentation.
There are two types of interceptors based on the execution model:
- Synchronous interceptor — Pipeline waits for interceptor completion
- Asynchronous interceptor — Pipeline continues while interceptor processes
// Synchronous interceptor
try await adk.intercept(interceptor: "my-interceptor") { payload, resolve, reject in
if let data = payload["data"] {
resolve([
"status": "success",
"data": data
])
} else {
reject("Failed")
}
}
// Asynchronous interceptor
try await adk.intercept(interceptor: "my-interceptor") { payload, resolve, reject in
// Run async work without blocking pipeline
Task {
print("🔀 Intercepted: on", payload)
// Simulate async work (API call, DB, etc.)
// let result = try await someAsyncFunction(payload)
resolve(payload)
}
}
Encrypted channel types cannot be intercepted — ART preserves complete privacy of user data on those channels.