start_agent.pyโข3.98 kB
#!/usr/bin/env python3
"""
Startup script for Jira-GitHub Agent
Provides easy way to start the agent with different configurations
"""
import argparse
import asyncio
import sys
from pathlib import Path
# Add parent directory to path for imports
sys.path.append(str(Path(__file__).parent.parent))
from jira_github_agent import JiraGitHubAgent
def parse_arguments():
"""Parse command line arguments"""
parser = argparse.ArgumentParser(
description="Start the Jira-GitHub Agent",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
python start_agent.py # Use default config
python start_agent.py --config custom.yaml # Use custom config
python start_agent.py --dry-run # Run in dry-run mode
python start_agent.py --test # Run tests first
"""
)
parser.add_argument(
'--config', '-c',
default='agents/agent_config.yaml',
help='Path to configuration file (default: agents/agent_config.yaml)'
)
parser.add_argument(
'--dry-run', '-d',
action='store_true',
help='Run in dry-run mode (no actual changes made)'
)
parser.add_argument(
'--test', '-t',
action='store_true',
help='Run tests before starting the agent'
)
parser.add_argument(
'--verbose', '-v',
action='store_true',
help='Enable verbose logging'
)
return parser.parse_args()
async def run_tests():
"""Run agent tests"""
print("๐งช Running agent tests...")
try:
from test_agent import run_all_tests
success = await run_all_tests()
return success
except ImportError:
print("โ Test module not found. Skipping tests.")
return True
except Exception as e:
print(f"โ Test execution failed: {e}")
return False
async def main():
"""Main entry point"""
args = parse_arguments()
print("๐ Jira-GitHub Agent Startup")
print("=" * 40)
# Run tests if requested
if args.test:
test_success = await run_tests()
if not test_success:
print("โ Tests failed. Aborting startup.")
sys.exit(1)
print("โ
All tests passed. Starting agent...\n")
# Create agent with specified config
try:
agent = JiraGitHubAgent(config_path=args.config)
print(f"๐ Using configuration: {args.config}")
# Override dry-run if specified
if args.dry_run:
agent.config['agent']['dry_run'] = True
print("๐งช Dry-run mode enabled")
# Override log level if verbose
if args.verbose:
agent.config['agent']['log_level'] = 'DEBUG'
print("๐ Verbose logging enabled")
# Display configuration summary
print("\n๐ Configuration Summary:")
print(f" Jira Project: {agent.config['jira']['project_key']}")
print(f" GitHub Repo: {agent.config['github']['repo_owner']}/{agent.config['github']['repo_name']}")
print(f" MCP Server: {agent.config['mcp']['host']}")
print(f" Check Interval: {agent.config['jira']['check_interval']}s")
print(f" Dry Run: {agent.config['agent']['dry_run']}")
print(f" Log Level: {agent.config['agent']['log_level']}")
# Start the agent
print("\n๐ฏ Starting agent monitoring...")
await agent.start()
except KeyboardInterrupt:
print("\nโน๏ธ Agent stopped by user")
except FileNotFoundError:
print(f"โ Configuration file not found: {args.config}")
print(" Please create the configuration file or specify a different path.")
sys.exit(1)
except Exception as e:
print(f"โ Failed to start agent: {e}")
sys.exit(1)
if __name__ == "__main__":
asyncio.run(main())