Skip to content

GuardedAgent

ai_guardian.integrations.anthropic.agent.GuardedAgent

Tool-use agent loop that scans every message for security threats.

Wraps an LLM API with an agentic tool-use loop. Every message — prompts, tool results, intermediate responses — is scanned for prompt injection, secrets, and PII via ai-guardian.

Auto-detects the provider from the client type and selects the matching loop strategy. Supports Anthropic (direct, Vertex AI, Bedrock) and OpenAI out of the box.

run(prompt, *, goal_state=None)

Run the agent loop and return the result.

When goal_evaluator is configured, goal_state is a fresh per-run state value passed to that callback after each successful assistant turn. The same value is returned in result["goal_state"].

Returns a dict with: - output: final text (or structured object if output_schema set) - messages: full conversation history - stop_reason: why the loop ended - usage: cumulative token usage