feat: Implement TAP (Titan Adapter Protocol) for framework-agnostic tool calling#25
feat: Implement TAP (Titan Adapter Protocol) for framework-agnostic tool calling#25
Conversation
…ling Phase 1: TAP Integration This commit integrates the Titan Adapter Protocol (TAP) into titan-cli, enabling autonomous multi-agent systems with tool calling capabilities. Key Changes: - Add TAP core components (protocol, registry, loader, factory, manager) - Add provider adapters (Anthropic, OpenAI, LangGraph) - Extend AIClient with generate_with_tools() method for autonomous agents - Add TAP configuration via YAML (config/tap/adapters.yml) - Create comprehensive example demonstrating TAP usage Architecture: - AIClient serves as facade that internally uses TAP - TAP provides framework-agnostic tool calling via Protocol pattern - Supports iterative agentic loops with multiple tool calls - Maintains backward compatibility with existing generate()/chat() methods New Capabilities: 1. Autonomous agent mode: AI decides which tools to use 2. Framework-agnostic: Works with Anthropic, OpenAI, etc. 3. Iterative execution: Agents can use multiple tools in sequence 4. Easy extensibility: Add new tools and providers via protocol Files Added: - titan_cli/tap/protocol.py - Core TAP protocol definition - titan_cli/tap/__init__.py - Public TAP API - titan_cli/tap/registry.py - Singleton adapter registry - titan_cli/tap/loader.py - Configuration-based adapter loading - titan_cli/tap/factory.py - Factory pattern for adapters - titan_cli/tap/manager.py - Complete lifecycle management - titan_cli/tap/adapters/anthropic.py - Anthropic adapter - titan_cli/tap/adapters/openai.py - OpenAI adapter - titan_cli/tap/adapters/langraph.py - LangGraph adapter - config/tap/adapters.yml - TAP configuration - examples/tap_integration_example.py - Usage examples Files Modified: - titan_cli/ai/client.py - Added TAP integration methods Next Steps (Phase 2): - Create multi-agent system base (titan_cli/agents/base.py) - Implement example agents (CodeReviewAgent, etc.) - Integrate agents with WorkflowContextBuilder Related: TitanAgents TAP implementation
Add complete test coverage for TAP (Titan Adapter Protocol) integration including adapter tests, manager tests, and AIClient integration tests. Tests Added: - tests/tap/test_adapters.py (16 tests) * Test Anthropic adapter conversion and execution * Test OpenAI adapter conversion and execution * Test adapter compatibility across providers * Mock TitanTool classes for testing - tests/tap/test_manager.py (31 tests) * Test TAPManager initialization and configuration * Test adapter registration and discovery * Test adapter loading from YAML/JSON configs * Test adapter caching and reload functionality * Test fallback strategies * Integration tests for complete workflows - tests/ai/test_client_tap.py (pending - will be added separately) * Test AIClient.generate_with_tools() method * Test iterative tool calling loops * Test max iterations limit * Test system prompts and parameter overrides Import Fixes: - Fixed imports in TAP modules (titan_cli.adapters → titan_cli.tap) - Removed TitanTool imports from adapters (use Any type) - Fixed adapters/__init__.py imports Test Results: - 43 of 47 tests passing (91.5% pass rate) - 4 failing tests are for builtin adapter auto-discovery (non-critical) - All core functionality tests pass: ✓ Tool conversion (Anthropic, OpenAI formats) ✓ Tool execution ✓ Manager lifecycle ✓ Configuration loading ✓ Registry operations Mock Implementation: - Created simplified TitanTool/ToolSchema/ToolParameter for testing - Avoids dependency on titan.core.tool module - Sufficient for testing TAP adapter functionality Next Steps: - Implement auto-discovery for builtin adapters - Add AIClient TAP integration tests - Add end-to-end integration tests
…est mocks - Wrap TAP adapter.get() in try-catch to raise AIConfigurationError instead of KeyError when adapter not found - Fix mock patches in test_client_tap.py to use correct import path (@patch('anthropic.Anthropic') instead of 'titan_cli.ai.client.anthropic.Anthropic') - All 11 AIClient TAP integration tests now passing Test Results: - 54 of 58 total TAP tests passing (93.1%) - All adapter conversion/execution tests pass ✓ - All manager lifecycle tests pass ✓ - All AIClient integration tests pass ✓ - Only 4 auto-discovery tests failing (non-critical)
Integrate TAP-powered autonomous AI agents for GitHub PR review workflows. New Features: - review_pr_step: General-purpose AI code review - analyze_pr_security_step: Security-focused review - analyze_pr_performance_step: Performance-focused review TAP-Compatible Tools Created: - GetPRFilesTool: Fetch list of changed files - GetPRCommentsTool: Get existing PR comments - AnalyzeCodeTool: Heuristic code analysis - SuggestImprovementTool: Generate improvement suggestions Workflow Capabilities: - Autonomous agent decides which tools to use - Iterative analysis with multiple tool calls - Structured review output with issues and suggestions - Optional auto-commenting on PRs - Specialized security and performance reviews Example Usage: ```python context.data['pr_number'] = 123 result = review_pr_step(context) result = analyze_pr_security_step(context) result = analyze_pr_performance_step(context) ``` Files Added: - plugins/titan-plugin-github/titan_plugin_github/steps/review_pr_step.py - plugins/titan-plugin-github/titan_plugin_github/tools.py - examples/github_pr_review_workflow.py Files Modified: - plugins/titan-plugin-github/titan_plugin_github/plugin.py This implements Phase 3 of the TAP integration plan: GitHub Plugin with autonomous AI agents for code review.
Add complete documentation for TAP (Titan Adapter Protocol) integration covering architecture, usage, best practices, and examples. Documentation Includes: - Architecture overview with diagrams - Component descriptions (Protocol, Adapters, Manager, AIClient) - Usage examples (basic tool calling, PR review agents) - Custom tool creation guide - Configuration reference - Testing guide with coverage metrics - Workflow examples - Best practices and troubleshooting - API reference - Performance metrics and optimization tips Key Sections: 1. Architecture - How TAP components work together 2. Usage Examples - From simple to complex workflows 3. Creating Custom Tools - Step-by-step guide 4. Configuration - YAML and TOML examples 5. Testing - Running and writing tests 6. Workflows - GitHub plugin integration 7. Best Practices - Tool design, prompts, error handling 8. Troubleshooting - Common issues and solutions 9. Performance - Metrics and optimization 10. API Reference - Detailed method documentation This completes the TAP integration documentation for titan-cli.
- Add comprehensive Python best practices documentation - Create test_tap_hello.py: Full example with AIClient integration - Create test_tap_hello_simple.py: Simplified TAP demonstration - Improve string formatting using f-strings consistently - Document when to use print vs logging - Add examples of proper type hints and error handling Examples demonstrate: - Complete functional path of generate_with_tools() - TAP manager initialization and adapter loading - Tool conversion and execution - Architecture visualization 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Wiz Scan Summary
To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension. |
| # Try JSON serialization for consistent hashing | ||
| try: | ||
| config_json = json.dumps(config, sort_keys=True) | ||
| config_hash = hashlib.md5(config_json.encode()).hexdigest()[:8] |
There was a problem hiding this comment.
Insecure Hashing Algorithm Usage (CWE-327)
More Details
The application is using an insecure or broken hashing algorithm like MD5 or SHA-1. These algorithms are vulnerable to collision attacks, meaning that two different input values can produce the same hash output. This undermines the cryptographic integrity of the hashing operation.
Using weak hashing algorithms for security-sensitive operations like password storage or digital signatures poses a significant risk. An attacker could potentially find collisions and impersonate users or forge data without knowing the original input. This could lead to unauthorized access, data tampering, or other security breaches.
To ensure the security of cryptographic operations, it is crucial to use modern, secure hashing algorithms like SHA-256, SHA-3, or Argon2id. These algorithms are designed to be resistant to collision attacks and provide stronger cryptographic guarantees.
| Attribute | Value |
|---|---|
| Impact | |
| Likelihood |
Remediation
Replace the usage of insecure hashing algorithms like MD5 or SHA-1 with secure alternatives like SHA-256, SHA-3, or Argon2id.
Recommendation:
- Use the
hashlibmodule in Python for secure hashing operations. - For password hashing, consider using the
bcryptorargon2libraries, which provide secure key derivation functions specifically designed for password storage.
Example using SHA-256:
import hashlib
data = b"sensitive_data"
sha256_hash = hashlib.sha256(data).hexdigest()Example using Argon2id for password hashing:
import argon2
password = b"secure_password"
hashed_password = argon2.hash_password_raw(password)Rule ID: WS-I011-PYTHON-00020
To ignore this finding as an exception, reply to this conversation with #wiz_ignore reason
If you'd like to ignore this finding in all future scans, add an exception in the .wiz file (learn more) or create an Ignore Rule (learn more).
To get more details on how to remediate this issue using AI, reply to this conversation with #wiz remediate
| # Try JSON serialization for consistent hashing | ||
| try: | ||
| config_json = json.dumps(config, sort_keys=True) | ||
| config_hash = hashlib.md5(config_json.encode()).hexdigest()[:8] |
There was a problem hiding this comment.
Usage of Insecure MD5 Hash Algorithm in Python hashlib Library (CWE-327)
More Details
The MD5 hash algorithm is considered insecure and should not be used for cryptographic purposes. MD5 is not collision-resistant, meaning that it is possible to find two different input messages that produce the same hash value. This vulnerability allows an attacker to forge digital signatures or conduct other attacks that undermine the integrity of data protected by MD5 hashes.
Using a weak or broken cryptographic algorithm like MD5 presents a significant security risk. If an attacker can exploit this vulnerability, they could potentially gain unauthorized access, tamper with data, or conduct other malicious activities. The consequences could include data breaches, system compromises, and other severe security incidents. To avoid this issue, use secure hash algorithms like SHA-256 or SHA-3 instead of MD5 for cryptographic operations.
| Attribute | Value |
|---|---|
| Impact | |
| Likelihood |
Remediation
The MD5 hash algorithm is considered insecure and should not be used for cryptographic purposes. MD5 is vulnerable to collision attacks, meaning that it is possible to find two different input messages that produce the same hash value. This makes MD5 unsuitable for applications that require collision resistance, such as digital signatures or file integrity checks.
To fix this issue, you should use a more secure hash algorithm, such as SHA-256 or SHA-3. These algorithms are designed to be collision-resistant and are recommended for cryptographic applications. In Python, you can use the hashlib module to compute SHA-256 or SHA-3 hashes.
Code examples:
// VULNERABLE CODE - Uses insecure MD5 hash algorithm
import hashlib
message = b"Hello, World!"
md5_hash = hashlib.md5(message).hexdigest()
print(md5_hash)
// SECURE CODE - Uses secure SHA-256 hash algorithm
import hashlib
message = b"Hello, World!"
sha256_hash = hashlib.sha256(message).hexdigest()
print(sha256_hash)
Additional recommendations:
- Follow industry best practices and use only cryptographically secure hash algorithms for security-related purposes.
- Consult relevant security standards, such as NIST SP 800-175B for recommendations on approved hash algorithms.
- Consider using a dedicated cryptographic library, such as PyCryptodome, which provides a higher level of abstraction and additional security features.
- If you need to support legacy systems that require MD5, clearly document the risks and limitations, and plan for a future migration to a secure algorithm.
Rule ID: WS-I013-PYTHON-00200
To ignore this finding as an exception, reply to this conversation with #wiz_ignore reason
If you'd like to ignore this finding in all future scans, add an exception in the .wiz file (learn more) or create an Ignore Rule (learn more).
To get more details on how to remediate this issue using AI, reply to this conversation with #wiz remediate
| The loaded class | ||
| """ | ||
| module_name, class_name = module_path.rsplit('.', 1) | ||
| module = importlib.import_module(module_name) |
There was a problem hiding this comment.
Arbitrary Code Execution via Insecure Import (CWE-706)
More Details
The importlib.import_module() function in Python allows dynamically importing modules at runtime. If the module name is derived from untrusted user input, an attacker could potentially execute arbitrary code on the system by causing a malicious module to be loaded.
| Attribute | Value |
|---|---|
| Impact | |
| Likelihood |
Remediation
The importlib.import_module() function in Python allows for dynamic code loading, which can be a security risk if the module name is derived from untrusted user input. An attacker could potentially exploit this vulnerability to execute arbitrary code on the system, leading to various security issues such as code injection, data tampering, or unauthorized access.
To fix this issue, avoid using dynamic values in importlib.import_module() or implement a strict whitelist of allowed module names. If dynamic module loading is necessary, validate and sanitize the input to ensure that only trusted and approved modules are loaded.
Code examples:
// VULNERABLE CODE - Directly using user input for module loading
import importlib
user_input = input("Enter module name: ")
module = importlib.import_module(user_input)
// SECURE CODE - Using a whitelist of allowed modules
import importlib
ALLOWED_MODULES = ["module1", "module2", "module3"]
user_input = input("Enter module name: ")
if user_input in ALLOWED_MODULES:
module = importlib.import_module(user_input)
else:
print("Module not allowed")
Additional recommendations:
- Follow the principle of least privilege and only grant the minimum required permissions for module loading.
- Implement input validation and sanitization techniques to prevent code injection attacks.
- Consider using a secure coding framework or library that provides built-in protection against code injection vulnerabilities.
- Adhere to the OWASP Top 10 security guidelines, specifically "A1:2021 - Broken Access Control" and "A3:2021 - Injection."
- Regularly update and maintain the whitelist of allowed modules to ensure it remains secure and up-to-date.
Rule ID: WS-I013-PYTHON-00176
To ignore this finding as an exception, reply to this conversation with #wiz_ignore reason
If you'd like to ignore this finding in all future scans, add an exception in the .wiz file (learn more) or create an Ignore Rule (learn more).
To get more details on how to remediate this issue using AI, reply to this conversation with #wiz remediate
| discovered = 0 | ||
|
|
||
| try: | ||
| module = importlib.import_module(package) |
There was a problem hiding this comment.
Arbitrary Code Execution via Insecure Import (CWE-706)
More Details
The importlib.import_module() function in Python allows dynamically importing modules at runtime. If the module name is derived from untrusted user input, an attacker could potentially execute arbitrary code on the system by causing a malicious module to be loaded.
| Attribute | Value |
|---|---|
| Impact | |
| Likelihood |
Remediation
The importlib.import_module() function in Python allows for dynamic code loading, which can be a security risk if the module name is derived from untrusted user input. An attacker could potentially exploit this vulnerability to execute arbitrary code on the system, leading to various security issues such as code injection, data tampering, or unauthorized access.
To fix this issue, avoid using dynamic values in importlib.import_module() or implement a strict whitelist of allowed module names. If dynamic module loading is necessary, validate and sanitize the input to ensure that only trusted and approved modules are loaded.
Code examples:
// VULNERABLE CODE - Directly using user input for module loading
import importlib
user_input = input("Enter module name: ")
module = importlib.import_module(user_input)
// SECURE CODE - Using a whitelist of allowed modules
import importlib
ALLOWED_MODULES = ["module1", "module2", "module3"]
user_input = input("Enter module name: ")
if user_input in ALLOWED_MODULES:
module = importlib.import_module(user_input)
else:
print("Module not allowed")
Additional recommendations:
- Follow the principle of least privilege and only grant the minimum required permissions for module loading.
- Implement input validation and sanitization techniques to prevent code injection attacks.
- Consider using a secure coding framework or library that provides built-in protection against code injection vulnerabilities.
- Adhere to the OWASP Top 10 security guidelines, specifically "A1:2021 - Broken Access Control" and "A3:2021 - Injection."
- Regularly update and maintain the whitelist of allowed modules to ensure it remains secure and up-to-date.
Rule ID: WS-I013-PYTHON-00176
To ignore this finding as an exception, reply to this conversation with #wiz_ignore reason
If you'd like to ignore this finding in all future scans, add an exception in the .wiz file (learn more) or create an Ignore Rule (learn more).
To get more details on how to remediate this issue using AI, reply to this conversation with #wiz remediate
Summary
Implements TAP (Titan Adapter Protocol), a framework-agnostic architecture for AI tool calling.
What's New
TAP Protocol
Built-in Adapters
Features
AIClient.generate_with_tools()- Unified tool calling APITest Plan
Next Steps
Foundation for multi-agent systems and complex tool orchestration.
🤖 Generated with Claude Code