This repository was archived by the owner on Jul 7, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmain.py
More file actions
79 lines (66 loc) · 2.45 KB
/
Copy pathmain.py
File metadata and controls
79 lines (66 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
AgentOS Entrypoint
==================
"""
from contextlib import asynccontextmanager
from os import getenv
from pathlib import Path
from agno.os import AgentOS
from agno.utils.log import log_info
from agents.code_search import code_search
from agents.web_search import web_search
from db import get_postgres_db
# ---------------------------------------------------------------------------
# Environment
# ---------------------------------------------------------------------------
runtime_env = getenv("RUNTIME_ENV", "prd")
scheduler_base_url = getenv("AGENTOS_URL", "http://127.0.0.1:8000")
# ---------------------------------------------------------------------------
# Interfaces
# - The CodeSearch agent becomes available on Slack when both env vars are set
# ---------------------------------------------------------------------------
SLACK_BOT_TOKEN = getenv("SLACK_BOT_TOKEN", "")
SLACK_SIGNING_SECRET = getenv("SLACK_SIGNING_SECRET", "")
interfaces: list = []
if SLACK_BOT_TOKEN and SLACK_SIGNING_SECRET:
from agno.os.interfaces.slack import Slack
interfaces.append(
Slack(
agent=code_search,
streaming=True,
token=SLACK_BOT_TOKEN,
signing_secret=SLACK_SIGNING_SECRET,
resolve_user_identity=True,
)
)
# ---------------------------------------------------------------------------
# Lifespan — extension hook for app-level startup / teardown.
#
# AgentOS handles the MCP lifecycle (connect on startup, close on shutdown).
# Keep this hook in place so you can plug in your own setup as needed.
# ---------------------------------------------------------------------------
@asynccontextmanager
async def lifespan(app): # type: ignore[no-untyped-def]
log_info("AgentOS lifespan: startup")
try:
yield
finally:
log_info("AgentOS lifespan: shutdown")
# ---------------------------------------------------------------------------
# Create AgentOS
# ---------------------------------------------------------------------------
agent_os = AgentOS(
name="AgentOS",
tracing=True,
scheduler=True,
scheduler_base_url=scheduler_base_url,
authorization=runtime_env == "prd",
lifespan=lifespan,
db=get_postgres_db(),
agents=[web_search, code_search],
interfaces=interfaces,
config=str(Path(__file__).parent / "config.yaml"),
)
app = agent_os.get_app()
if __name__ == "__main__":
agent_os.serve(app="app.main:app", reload=runtime_env == "dev")