Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jun 24, 2025

This PR implements a complete Python agent framework that provides equivalent functionality to the existing Java agent, enabling full integration with the Sentrius platform APIs.

Overview

The Python agent now supports all the same operations as the Java agent:

  • Authentication: Keycloak JWT token management and validation
  • Registration: Automatic agent registration with the API server
  • Heartbeat: Continuous monitoring and status reporting
  • Provenance: Detailed event submission for audit trails
  • Security: RSA key generation for encrypted communication

Key Components Added

Core Services

  • KeycloakService: Handles JWT validation, token retrieval, and Keycloak integration
  • AgentClientService: Manages all API communication (registration, heartbeat, provenance submission)
  • EphemeralKeyGen: RSA key generation and cryptographic operations
  • SentriusAgent: Main orchestration framework coordinating all services

Agent Framework

  • Enhanced BaseAgent: Abstract base class with full Sentrius integration
  • Updated SQLAgent: Example implementation with provenance tracking and LLM support
  • Configuration management: Support for YAML files and environment variables

API Endpoints Supported

  • POST /api/v1/agent/register - Agent registration
  • POST /api/v1/agent/heartbeat - Status monitoring
  • POST /api/v1/agent/provenance/submit - Event submission
  • Session management endpoints

Usage Examples

Basic Agent Execution

# With configuration file
python main.py sql_agent --config config.yaml

# Using environment variables
export KEYCLOAK_SERVER_URL=http://localhost:8080
export KEYCLOAK_CLIENT_ID=python-agent
python main.py sql_agent

Custom Agent Development

from agents.base import BaseAgent

class MyCustomAgent(BaseAgent):
    def execute_task(self):
        self.submit_provenance("CUSTOM_TASK", {"operation": "data_processing"})
        # Your agent logic here

Configuration

keycloak:
  server_url: "http://localhost:8080"
  realm: "sentrius"
  client_id: "python-agent"
  client_secret: "your-secret"

agent:
  name_prefix: "python-agent"
  api_url: "http://localhost:8080"
  heartbeat_interval: 30

Testing

  • Unit tests: Complete coverage for all core services
  • Integration tests: End-to-end validation with mocked dependencies
  • Error handling: Graceful degradation for missing configurations

Compatibility

The Python agent is fully compatible with the existing Java infrastructure:

  • Uses identical API endpoints and data formats
  • Supports the same authentication mechanisms
  • Can be deployed alongside Java agents
  • Compatible with the agent launcher service

Files Added/Modified

  • New: python-agent/services/ - Core service implementations
  • New: python-agent/tests/ - Comprehensive test suite
  • New: python-agent/README.md - Documentation and usage guide
  • Enhanced: python-agent/agents/base.py - Integration framework
  • Enhanced: python-agent/agents/sql_agent/sql_agent.py - Updated with Sentrius integration
  • Updated: python-agent/requirements.txt - Added necessary dependencies

Fixes #51.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Create a python agent Create comprehensive Python agent with full Sentrius API integration Jun 24, 2025
Copilot AI requested a review from phrocker June 24, 2025 13:12
@phrocker
Copy link
Contributor

Great stuff. Can we remove the SQL agent? You may notice that all interactions are through APIs ( once a jwt is obtained ), meaning that the python agent won't have access to the database directly -- only via DTOs from the API and the LLM proxy.

Copy link
Contributor Author

Copilot AI commented Jun 24, 2025

Great stuff. Can we remove the SQL agent? You may notice that all interactions are through APIs ( once a jwt is obtained ), meaning that the python agent won't have access to the database directly -- ...

SQL agent removed per your feedback. The Python agent framework now focuses on API-based interactions using DTOs and the LLM proxy, without direct database access. All SQL-related dependencies and examples have been cleaned up. (commit 6dff466)

parser = argparse.ArgumentParser(description="Run selected agent.")
parser = argparse.ArgumentParser(description="Run selected Sentrius Python agent.")
parser.add_argument(
"agent",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. In the java side we have the application.properties that defines a link to a yaml file that can be used for the context of defining what an agent does. If you look in src and under resources you'll see chat-helper.yaml and chat-helper.properties. Can we do something similar here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've implemented a properties-based configuration system similar to the Java side. The Python agent now uses application.properties that references YAML files for agent definitions, just like the Java agent's approach with chat-helper.yaml and chat-helper.properties.

Key features added:

  • application.properties with environment variable substitution (${VARIABLE:default})
  • Agent-specific YAML files (chat-helper.yaml, data-analyst.yaml, terminal-helper.yaml)
  • ConfigManager that loads both properties and referenced YAML files
  • Test mode for development without external services

Usage: python main.py chat-helper --config application.properties (commit 5941b76)

Copilot AI requested a review from phrocker June 24, 2025 14:13
@phrocker phrocker marked this pull request as ready for review June 24, 2025 14:18
@phrocker phrocker merged commit 08fd5d5 into main Jun 24, 2025
4 checks passed
@phrocker phrocker deleted the copilot/fix-51 branch June 30, 2025 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a python agent

2 participants