Skip to content

Latest commit

 

History

History

PhiData_Agent_Examples

🚀 AIShield Guardian 🛡️ x Phidata Integration ⚙️

Agentic AI Security for Safe, Secure and, Policy-Compliant Workflows at Enterprise Scale

Transform your enterprise's Agentic AI workflows with the integration of AIShield Guardian and Phidata. Designed to actively monitor, validate, and guard every step, this integration empowers Agentic AI to operate securely, safely and responsibly at enterprise scale.

Join us in securing the future of Agentic AI today!

🔐 See Agentic Security in Action in this youtube video.

Watch the video

📜 Overview

Integrate AIShield Guardian (Link) with Phidata (Link) for an all-in-one, policy-compliant, safe and secure agents and workflow system!

This reference implementation showcases the integration of the Guardian API with Phidata agents to effectively monitor, validate, and manage agents and their workflows. By leveraging agents for planning and execution, it creates a secure, policy-compliant framework enhanced by automated oversight. The Guardian API acts as a critical safeguard, enforcing content standards, preventing inappropriate agent or workflow progressions, and securing outputs within configurable compliance boundaries.

With Guardian as your compliance and security guardrail, you can safeguard every agent and workflow within Phidata's multi-agent platform at every stage with built-in checks, ensuring that only safe, approved content is processed with Agentic AI.

🔑 Key Takeaways

  1. Policy Enforcement: Guardian actively monitors and halts non-compliant inputs and outputs, enforcing policy at every stage and step! As a guardrail, it intervenes whenever necessary, even during intermediate stages, to prevent any operations that do not meet compliance standards.

  2. Automated Monitoring and Improved Compliance: From start to finish, Guardian automates validations and reduces manual reviews. Guardian streamlines validations and flags anomalies in real time, ensuring a more efficient and reliable monitoring process.

  3. Enhanced Security: Detect and block (if needed) unauthorized, sensitive content or malicious content, ensuring compliant workflows every time. Guardian secures agent workflows against any unauthorized, malicious or sensitive content.

⚙️ Technical Highlights

  • GuardedAgentWorkflow Class: Created a new agentic workflow class to integrate Guardian with agent. Manages workflow processes, running prompts through compliance checks and the agent model at every step.

  • Guardian API Classes: GuardianAPIConfig and GuardianAPIClient ensure secure API handling, retry mechanisms, and compliance validation across all project stages.

  • Modular Configurations: Any Agents can be added to the GuardedAgentWorkflow in modular fashion, enabling easy customization and scalable, reusable workflows.


Table of Contents


🏁 Getting Started

📋 Prerequisites

  • Phidata (Refer this guide)

  • Required libraries:

    pip install -r requirement.txt

🛠️ Installation & Setup

  1. Clone the repo and configure environment variables for working with Guardian:

    export GUARDIAN_API_ENDPOINT="https://your-guardian-api-endpoint.com"
    export GUARDIAN_API_KEY="your_guardian_api_key"
  • 📝 NOTE: For getting your GUARDIAN_API_ENDPOINT and GUARDIAN_API_KEY, please Contact Us.
  1. Configure environment variables for working with your preferred choice of LLM (Refer this Model guide provided by Phidata).

▶️ Run the Example

To start the financial agent (Phidata reference agent implementation without guardrail) and run example prompts through Guardian validation, execute:

python finance_agent_guardian_api.py

This will validate user prompts and model outputs, ensuring they meet policy standards before delivering results.

💻 Example Code

Here's an example of how a prompt is processed with GuardedAgentWorkflow:

from guardian_workflow import GuardedAgentWorkflow
from guardian_api import GuardianAPIConfig
from phi.agent import Agent

# Define Guardian configuration and agent setup
guardian_config = GuardianAPIConfig(api_key="your_api_key", base_url="https://your-guardian-api-endpoint.com")
workflow = GuardedAgentWorkflow(agent=financial_agent, guardian_config=guardian_config, prompts=["Your prompt"], guardrail_config={"active": True})

# Run the workflow
workflow.run()

🔐 See Agentic Security in Action

Click to watch youtube video.

Watch the video


If you want to know more about its usage and implications,


🔧 Technical Details

The integration of Guardian API within Phidata adds a layer of validation and monitoring to ensure each agent and workflow adheres to specified policies. This section provides an in-depth overview of key components in this setup.

🔌 GuardianAPIClient 🛡️

The GuardianAPIClient class is responsible for interacting with the Guardian API. It centralizes request handling, enabling secure and reliable data exchange.

  • Initialization: Configures a base URL and optional API key with authorization headers.
    • 📝 NOTE: For getting your GUARDIAN_API_ENDPOINT and GUARDIAN_API_KEY, please Contact Us.
  • GET and POST Methods: Simplify API communication, including error handling for logging issues.
  • Endpoints:
    • Configuration: Retrieves configuration details.
    • Dashboard Summary: Provides an overview of system usage.
    • Query History: Accesses historical API queries.
    • Chat API: Validates prompts for policy compliance.
    • LLM Configuration and Mode Configuration: Adjust settings for large language models (e.g., Llama) and operational modes.
  • Connectivity Check: Uses retry to ensure Guardian API availability at runtime.

✔️ CheckResult

CheckResult represents the result of data validation checks performed by Guardian API with:

  • Approved: Boolean flag indicating compliance.
  • Message: Provides details on compliance or policy violations.

🔐 GuardianAPIConfig

GuardianAPIConfig wraps GuardianAPIClient for structured input and output validation.

  • Input Validation (check_input): Screens prompts for policy compliance.
  • Output Validation (check_output): Ensures generated content adheres to policies, flagging violations.

🛡️ GuardedAgentWorkflow

The GuardedAgentWorkflow class integrates an AI agent with the Guardian API, enforcing compliance checks on inputs and outputs through configurable guardrails.

  • Initialization: Takes agent, guardian_config, prompts, and guardrail_config.
  • Prompt Processing: Validates the prompt to ensure it’s usable.
  • Guardian Input Check: Checks input compliance using Guardian if enabled.
  • Agent Execution: Sends the prompt to the agent and retrieves the response.
  • Guardian Output Check: Validates the agent’s output for compliance.
  • Result Display: Shows the agent’s validated response in a readable format.
  • Workflow Execution: Runs the complete process for each prompt, ensuring policy compliance at each step.

🗂️ Agent and Workflow Configuration

The Phidata Agent Framework is designed for building and managing agentic systems. It supports:

  • Agent Creation: Enables agents with memory, knowledge, tools, and reasoning capabilities.
  • Agent Teams: Allows collaboration between agents for complex tasks.
  • Extensibility: Integrates with various tools, knowledge bases, and vector databases.

The GuardedAgentWorkflow class can integrate with this framework, applying compliance checks seamlessly across various agents within Phidata's modular system. More details can be found here.

This configuration enables scalability and adaptability by allowing agent customization per project.


If you want to know more on technical integration and how to run in your environment,


⚖️ License

This project is licensed under MIT License.