This implementation adds a sophisticated coding agent to the Sentrius platform that automates code generation and pull request submission through GitHub and JIRA integrations.
From issue: "when using jira or github integrations there may be coding tasks an agent can do. We should allow agents to write the code and complete that task and submit a PR."
A full-featured Python agent that:
- Accepts coding tasks from multiple sources (JIRA, GitHub, direct)
- Generates production-ready code using LLM integration
- Creates pull requests automatically via GitHub MCP server
- Updates JIRA issues with PR links
- Maintains complete audit trails via provenance tracking
-
Coding Agent (
agents/coding/coding_agent.py)- 600+ lines of production code
- Implements BaseAgent interface
- Integrates with existing Sentrius infrastructure
-
Integration Points:
- GitHub MCP Server: For repository operations (existing)
- JIRA Proxy: For issue management (existing)
- LLM Proxy: For AI-powered code generation (existing)
- Keycloak: For authentication (existing)
- Provenance System: For audit trails (existing)
-
Configuration (
coding.yaml):- LLM model selection
- Integration service URLs
- GitHub token management
- System prompts for code quality
JIRA Issue → Fetch Details → Generate Code (LLM) → Create PR → Update JIRA
Steps:
- Fetch issue from JIRA proxy (
/api/v1/jira/rest/api/3/issue/{key}) - Extract requirements (summary, description)
- Generate code using LLM proxy with structured prompt
- Launch/verify GitHub MCP server
- Create branch (
automated/{sanitized-title}) - Commit changes
- Create pull request
- Add comment to JIRA with PR link
GitHub Issue → Fetch Details (MCP) → Generate Code (LLM) → Create PR
Steps:
- Fetch issue via GitHub MCP server
- Extract requirements (title, body)
- Generate code using LLM proxy
- Create branch and commit via MCP server
- Create pull request
Code Changes → Create Branch → Commit → Create PR
Steps:
- Validate pre-generated code changes
- Create branch via MCP server
- Commit files
- Create pull request
Prompt Engineering:
- System context defines coding standards
- Structured output format (JSON)
- Context-aware (language, framework, requirements)
Response Format:
{
"files": [
{
"path": "src/main/java/Example.java",
"content": "public class Example { ... }",
"operation": "create|update|delete"
}
],
"explanation": "Brief explanation of changes"
}- All operations require Keycloak JWT authentication
- GitHub operations through MCP server proxy (zero trust)
- JIRA operations through authenticated proxy
- No direct database access
- Complete provenance tracking
Webhook Integration:
- JIRA webhook handler script
- GitHub webhook handler script
- Python automation wrapper
CI/CD Examples:
- GitHub Actions workflow
- Jenkins pipeline
- GitLab CI configuration
- Graceful degradation
- Comprehensive error logging
- Provenance event tracking for failures
- Automatic GitHub MCP server launch
- Comment failures don't fail entire operation
test_agent_initialization- Verify agent setuptest_execute_task_test_mode- Test mode executiontest_sanitize_branch_name- Branch naming logictest_build_coding_prompt- Prompt constructiontest_parse_llm_code_response_valid_json- JSON parsingtest_parse_llm_code_response_invalid_json- Error handlingtest_get_agent_info- Agent metadatatest_invalid_operation- Error casestest_missing_required_fields- Input validationtest_full_workflow- Integration test (skipped in test mode)
TEST_MODE=trueenvironment variable- No external service dependencies
- Useful for development and CI/CD
# Keycloak Authentication
KEYCLOAK_BASE_URL=http://localhost:8180
KEYCLOAK_CLIENT_ID=python-agents
KEYCLOAK_CLIENT_SECRET=your-secret
# Integration Services
INTEGRATION_PROXY_URL=http://localhost:8080
LLM_PROXY_URL=http://localhost:8080
# GitHub Configuration
GITHUB_TOKEN_ID=1 # IntegrationSecurityToken ID
# LLM Configuration
LLM_MODEL=gpt-4
# Optional
TEST_MODE=falseagent.coding.config=python-agent/coding.yaml
agent.coding.enabled=truepython main.py coding --task-data '{
"operation": "handle_jira_issue",
"issue_key": "PROJECT-123",
"repo": "owner/repository",
"context": {
"language": "Python",
"framework": "Flask"
}
}'python main.py coding --task-data '{
"operation": "handle_github_issue",
"repo": "owner/repository",
"issue_number": 456,
"context": {
"language": "Java",
"framework": "Spring Boot"
}
}'from automation_example import CodingAgentAutomation
automation = CodingAgentAutomation()
result = automation.handle_jira_issue(
issue_key="PROJECT-123",
repo="owner/repository",
context={"language": "Python"}
)python-agent/
├── agents/
│ └── coding/
│ ├── __init__.py
│ ├── coding_agent.py # Main agent (600+ lines)
│ └── README.md # Agent documentation
├── examples/
│ ├── README.md # Integration examples
│ ├── automation_example.py # Python wrapper
│ ├── jira-webhook-handler.sh # JIRA integration
│ └── github-webhook-handler.sh # GitHub integration
├── tests/
│ └── test_coding_agent.py # Unit tests
├── coding.yaml # Agent configuration
├── application.properties # Enabled agent
└── main.py # Registered agent
execute_task()- Main entry point_handle_jira_issue()- JIRA workflow_handle_github_issue()- GitHub workflow_create_pull_request()- PR creation_generate_code_with_llm()- Code generation_ensure_github_mcp_server()- MCP server management_call_github_mcp_tool()- MCP proxy communication
requests- HTTP clientPyJWT- JWT handlingcryptography- Encryptionpyyaml- Configurationwebsockets- MCP communication
- Keycloak - Authentication server
- Integration Proxy - GitHub/JIRA proxy
- LLM Proxy - Code generation
- GitHub MCP Server - Repository operations (containerized)
- Kubernetes - For MCP server deployment
- ✅ No security vulnerabilities detected
- ✅ No code quality issues
- ✅ Clean scan
- Authentication: All operations require valid JWT tokens
- Authorization: Keycloak-based access control
- Zero Trust: GitHub operations through MCP server proxy
- Audit Trail: Complete provenance tracking
- No Secrets in Code: Environment variable based configuration
- Input Validation: Sanitization of user inputs (branch names, etc.)
- Minimal memory footprint (Python agent)
- Ephemeral GitHub MCP server pods (launched on-demand)
- LLM calls may take 10-30 seconds depending on complexity
- Overall workflow: 30-60 seconds per task
- Stateless agent design
- Can be horizontally scaled
- MCP server auto-launched per token
- Kubernetes-based deployment
- Single branch per PR (no multi-branch support)
- Manual conflict resolution required
- No automated testing of generated code
- English-only prompts
- No code review automation
- Testing Integration: Automatically test generated code
- Multi-Repository Support: Handle cross-repo changes
- Code Review: Integrate with review tools
- Conflict Resolution: Automatic merge conflict handling
- GitLab/Bitbucket: Support additional platforms
- Advanced Analytics: Track code quality metrics
- Learning: Improve prompts based on feedback
cd python-agent
pip install -r requirements.txt
TEST_MODE=true python main.py coding --task-data '{...}'# Add to values.yaml
codingAgent:
enabled: true
image:
repository: sentrius-coding-agent
tag: latest
env:
- name: GITHUB_TOKEN_ID
value: "1"See examples/README.md for GitHub Actions, Jenkins, and GitLab CI examples.
agents/coding/README.md- Comprehensive agent guideexamples/README.md- Integration patterns and examplespython-agent/README.md- Updated with coding agent section- This document - Technical implementation details
[INFO] BUILD SUCCESS
[INFO] Total time: 53.451 s
Ran 10 tests in 0.027s
OK (skipped=1)
Analysis Result for 'python'. Found 0 alerts:
- **python**: No alerts found.
This implementation provides a production-ready coding agent that:
- ✅ Solves the stated problem (automated coding via JIRA/GitHub)
- ✅ Integrates seamlessly with existing infrastructure
- ✅ Maintains security and audit requirements
- ✅ Provides comprehensive documentation
- ✅ Includes examples and automation templates
- ✅ Passes all tests and security scans
- ✅ Is ready for deployment
The agent leverages existing Sentrius components (GitHub MCP, JIRA proxy, LLM proxy) and adds minimal new code while providing powerful automation capabilities.