Before you begin
Initialize the TypeScript or Python client asfw. Supply your model, tools, and a conversation ID for the agent sequence.
Choose Shadow or Warn explicitly for observation. Effective Block mode replaces denied tool interactions and model content with safe messages. Classification failures allow execution by default. Set failOpen: false in TypeScript or fail_open: False in Python when a successful classification is required.
Create a protected agent
Deep Agents creates its own subagent graphs. Use the protected constructor to cover the root, its general-purpose subagent, and declarative subagents. In the examples below, supply your initializedfw, configured chat model, tools
array or list, and a caller-generated conversationId or conversation_id for
this agent sequence.
- TypeScript
- Python
Location: your service project directoryLocation: protected agent applicationFor a compiled subagent, use the verified factory before creating the parent:Location: protected agent application
createProtectedCompiledSubagent in TypeScript or
create_protected_compiled_subagent in Python. These helpers install Silmaril
middleware before compiling the graph. Pass the returned spec through
protectedCompiledSubagents or protected_compiled_subagents, respectively.
The parent constructor verifies the exact graph and Firewall client and rejects
an arbitrary compiled runnable. Root custom middleware does not automatically
reach every subagent. Classification errors allow execution by default. Set
silmaril: { failOpen: false } in TypeScript or
middleware_options={"fail_open": False} in Python when execution requires a
successful classification.
The middleware checks user input before model use, tool calls before execution,
tool results before the next model call, and non-streamed model output before
the graph consumes it. In Block mode, denied tool calls and results become a
fixed safe tool message with the original call ID. The agent may choose an
allowed alternative. Repeated denials end with a fixed safe response. Denied
model output is replaced before it enters graph messages. Shadow and Warn
report decisions without replacing content. Already emitted streaming text
cannot be recalled.
TypeScript SDK 0.7.3 and later apply the repeated-denial cap only in effective Block
mode. Genuine earlier Block denials remain counted, but do not halt Warn or
Shadow continuation.