-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (43 loc) · 2.07 KB
/
Copy pathmain.py
File metadata and controls
51 lines (43 loc) · 2.07 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
import os
import warnings
from agenticlayer.adk.agent_to_a2a import to_a2a
from agenticlayer.adk.otel import setup_otel
from agenticlayer.shared.config import parse_sub_agents, parse_tools
from dotenv import load_dotenv
from google.adk.agents import LlmAgent
from google.adk.models.lite_llm import LiteLlm
from google.adk.planners import BuiltInPlanner
from google.genai import types
from loguru_config import setup_logging
# Load environment variables from .env file
load_dotenv()
# Set up logging
setup_logging()
if os.environ.get("AGENT_OTEL_ENABLED", "true").lower() == "true":
setup_otel()
# Suppress some warnings by default - unfortunately, the experimental warnings for A2A can not be suppressed
# using the ADK environment variable alone, so we filter them here.
warnings.filterwarnings("ignore", category=UserWarning, message="\\[EXPERIMENTAL\\] .*")
os.environ.setdefault("ADK_SUPPRESS_GEMINI_LITELLM_WARNINGS", "true")
os.environ.setdefault("ADK_SUPPRESS_EXPERIMENTAL_FEATURE_WARNINGS", "true")
# The agent url is needed for the agent card to tell other agents how to reach this agent.
# We can only guess the host and port here, as it may be set differently by Uvicorn at runtime.
# If running in k8s or similar, the host and port may also be different.
port = os.environ.get("UVICORN_PORT", 8000)
app = to_a2a(
agent=LlmAgent(
name=os.environ.get("AGENT_NAME", "root_agent"),
model=LiteLlm(os.environ.get("AGENT_MODEL", "gemini/gemini-2.5-flash")),
description=os.environ.get("AGENT_DESCRIPTION", ""),
instruction=os.environ.get("AGENT_INSTRUCTION", ""),
planner=BuiltInPlanner(
thinking_config=types.ThinkingConfig(
include_thoughts=os.environ.get("AGENT_INCLUDE_THOUGHTS", "True").lower() == "true",
thinking_budget=int(os.environ.get("AGENT_THINKING_BUDGET", 1024)),
)
),
),
rpc_url=os.environ.get("AGENT_A2A_RPC_URL", f"http://localhost:{port}"),
sub_agents=parse_sub_agents(os.environ.get("SUB_AGENTS", "{}")),
tools=parse_tools(os.environ.get("AGENT_TOOLS", "{}")),
)