Skip to content

Commit 97f2518

Browse files
feat(sdk): 57143 strands extra (#59)
Summary Added Strands integration as a vendor-owned subpackage in agent-control-sdk[strands-agents] (AgentControlHook + AgentControlSteeringHandler) and updated Strands examples to use the new import path with controls attached directly to agents. Scope User-facing/API changes: New integration import path: agent_control.integrations.strands. New optional extra: agent-control-sdk[strands-agents] (min Strands version 1.26.0). Internal changes: Added Strands integration modules to SDK. Added evaluate_controls tests and restored missing convenience helpers. Updated examples to remove common/ and policy wiring; controls are attached to agents. Out of scope: Strands repo changes beyond example integration. Risk and Rollout Risk level: medium Rollback plan: Revert SDK integration subpackage and example changes; release prior SDK version. Testing Added or updated automated tests Ran make check (or explained why not) Manually verified behavior Checklist Linked issue/spec (if applicable) Updated docs/examples for user-facing changes Included any required follow-up tasks
1 parent 70016db commit 97f2518

20 files changed

Lines changed: 4586 additions & 66 deletions
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# AgentControl Server
2+
AGENT_CONTROL_URL=http://localhost:8000
3+
4+
# OpenAI API Key (required for Strands agents)
5+
OPENAI_API_KEY=your_openai_api_key_here
6+
7+
# Galileo API Key (optional - for Galileo evaluators)
8+
GALILEO_API_KEY=your_galileo_api_key_here
9+
10+
# Galileo Console URL (optional)
11+
GALILEO_CONSOLE_URL=https://console.galileo.ai

‎examples/strands_agents/README.md‎

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# AgentControl + Strands Integration
2+
3+
Automatic safety controls for AWS Strands agents using hooks - no decorators needed.
4+
5+
## Quick Start
6+
7+
**Prerequisites:** Python 3.12+, OpenAI API key, AgentControl server
8+
9+
```bash
10+
# 1. Install
11+
cd examples/strands_integration
12+
uv pip install -e .
13+
14+
# 2. Configure
15+
cp .env.example .env
16+
# Edit .env: Add OPENAI_API_KEY and AGENT_CONTROL_URL
17+
18+
# 3. Start server (Terminal 1)
19+
curl -fsSL https://raw.githubusercontent.com/agentcontrol/agent-control/docker-compose.yml | docker compose -f - up -d
20+
21+
# 4. Setup controls (Terminal 2)
22+
cd examples/strands_integration/interactive_demo
23+
uv run setup_interactive_controls.py
24+
25+
# 5. Run demo (Terminal 3)
26+
streamlit run interactive_support_demo.py
27+
```
28+
29+
Open http://localhost:8501 and click test buttons to see safety controls in action.
30+
31+
## Available Demos
32+
33+
### [Interactive Demo](interactive_demo/)
34+
Customer support agent with PII blocking and SQL injection prevention. Shows real-time safety checks in Streamlit UI.
35+
36+
### [Steering Demo](steering_demo/)
37+
Banking email agent with PII redaction. Combines AgentControl Hook (deny on tool calls) + Strands Steering (steer on LLM draft) for layered governance. Uses a two-phase draft → send flow so steer can guide before tool calls.
38+
39+
## How It Works
40+
41+
**AgentControlHook** = Automatic safety without code changes
42+
43+
```python
44+
from agent_control.integrations.strands import AgentControlHook
45+
from strands import Agent
46+
47+
# Initialize
48+
import agent_control
49+
agent_control.init(agent_name="my-customer-agent")
50+
51+
# Create hook
52+
hook = AgentControlHook(agent_name="my-customer-agent")
53+
54+
# Attach to agent - done!
55+
agent = Agent(
56+
model=model,
57+
system_prompt="...",
58+
tools=[...],
59+
hooks=[hook] # All safety checks automated
60+
)
61+
```
62+
63+
**Hook intercepts events** → **Server evaluates controls** → **Blocks unsafe actions**
64+
65+
For steer actions, the steering handler converts AgentControl steer into a Strands `Guide()` retry.
66+
67+
## Controls
68+
69+
**LLM Controls** - Apply to all model interactions:
70+
```python
71+
{
72+
"scope": {"step_types": ["llm"], "stages": ["pre"]},
73+
"evaluator": {"name": "regex", "config": {"pattern": r"\d{3}-\d{2}-\d{4}"}},
74+
"action": {"decision": "deny"}
75+
}
76+
```
77+
78+
**Tool Controls** - Target specific tools:
79+
```python
80+
{
81+
"scope": {
82+
"step_types": ["tool"],
83+
"step_names": ["lookup_order"], # Only this tool
84+
"stages": ["pre"]
85+
},
86+
"evaluator": {"name": "regex", "config": {"pattern": r"ORD-\d+"}},
87+
"action": {"decision": "deny"}
88+
}
89+
```
90+
91+
Hook automatically extracts tool names from events - no decorators needed!
92+
93+
## Architecture
94+
95+
```
96+
User Input
97+
↓
98+
Strands fires event (BeforeToolCallEvent, AfterModelCallEvent, etc.)
99+
↓
100+
AgentControlHook intercepts → Creates Step → Calls AgentControl server
101+
↓
102+
Server evaluates controls → Returns safe/unsafe
103+
↓
104+
Hook enforces decision: Continue ✅ or Block ❌
105+
```
106+
107+
## Integration Patterns
108+
109+
**Basic setup**:
110+
```python
111+
hook = AgentControlHook(
112+
agent_name="my-customer-agent",
113+
enable_logging=True
114+
)
115+
```
116+
117+
**Steering integration**:
118+
- `AgentControlHook` for tool-stage deny (hard blocks)
119+
- `AgentControlSteeringHandler` for LLM steer → `Guide()` (corrective guidance)
120+
121+
See `steering_demo/README.md` for complete implementation.
122+
123+
## Troubleshooting
124+
125+
**"AgentControl not initialized"**
126+
- Run `agent_control.init()` before creating hook
127+
128+
**Controls not triggering**
129+
- Server running? `curl http://localhost:8000/health`
130+
- Controls exist? Re-run `setup_*_controls.py`
131+
132+
**Import errors**
133+
- Install deps: `uv sync` or `pip install -e .`
134+
135+
## Files
136+
137+
- `interactive_demo/` - Customer support demo with PII/SQL injection blocking
138+
- `steering_demo/` - Banking email demo with PII redaction

0 commit comments

Comments
 (0)