This commit removes deprecated modules and reorganizes code into logical directories: Deleted files (superseded by newer systems): - claude_code_server.py (replaced by agent-sdk direct integration) - heartbeat.py (superseded by scheduled_tasks.py) - pulse_brain.py (unused in production) - config/pulse_brain_config.py (obsolete config) Created directory structure: - examples/ (7 example files: example_*.py, demo_*.py) - tests/ (5 test files: test_*.py) Updated imports: - agent.py: Removed heartbeat module and all enable_heartbeat logic - bot_runner.py: Removed heartbeat parameter from Agent initialization - llm_interface.py: Updated deprecated claude_code_server message Preserved essential files: - hooks.py (for future use) - adapters/skill_integration.py (for future use) - All Google integration tools (Gmail, Calendar, Contacts) - GLM provider code (backward compatibility) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
76 lines
1.9 KiB
Python
76 lines
1.9 KiB
Python
"""
|
|
Example: Using the adapter system programmatically.
|
|
|
|
Demonstrates how to integrate adapters into your own code,
|
|
rather than using the bot_runner.py CLI.
|
|
"""
|
|
|
|
import asyncio
|
|
|
|
from adapters.base import AdapterConfig
|
|
from adapters.runtime import (
|
|
AdapterRuntime,
|
|
command_preprocessor,
|
|
markdown_postprocessor,
|
|
)
|
|
from adapters.slack.adapter import SlackAdapter
|
|
from adapters.telegram.adapter import TelegramAdapter
|
|
from agent import Agent
|
|
|
|
|
|
async def main() -> None:
|
|
# 1. Create the agent
|
|
agent = Agent(
|
|
provider="claude",
|
|
workspace_dir="./memory_workspace",
|
|
enable_heartbeat=False,
|
|
)
|
|
|
|
# 2. Create runtime
|
|
runtime = AdapterRuntime(agent)
|
|
|
|
# 3. Add preprocessors and postprocessors
|
|
runtime.add_preprocessor(command_preprocessor)
|
|
runtime.add_postprocessor(markdown_postprocessor)
|
|
|
|
# 4. Configure Slack adapter
|
|
slack_adapter = SlackAdapter(AdapterConfig(
|
|
platform="slack",
|
|
enabled=True,
|
|
credentials={
|
|
"bot_token": "xoxb-YOUR-TOKEN",
|
|
"app_token": "xapp-YOUR-TOKEN",
|
|
},
|
|
))
|
|
runtime.add_adapter(slack_adapter)
|
|
|
|
# 5. Configure Telegram adapter
|
|
telegram_adapter = TelegramAdapter(AdapterConfig(
|
|
platform="telegram",
|
|
enabled=True,
|
|
credentials={"bot_token": "YOUR-TELEGRAM-TOKEN"},
|
|
settings={"parse_mode": "Markdown"},
|
|
))
|
|
runtime.add_adapter(telegram_adapter)
|
|
|
|
# 6. Map users (optional)
|
|
runtime.map_user("slack:U12345", "alice")
|
|
runtime.map_user("telegram:123456789", "alice")
|
|
|
|
# 7. Start runtime
|
|
await runtime.start()
|
|
|
|
# 8. Keep running
|
|
try:
|
|
print("Bot is running! Press Ctrl+C to stop.")
|
|
while True:
|
|
await asyncio.sleep(1)
|
|
except KeyboardInterrupt:
|
|
print("\nStopping...")
|
|
finally:
|
|
await runtime.stop()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|