1515
1616import inspect
1717import logging
18+ import os
1819from functools import wraps
1920from typing import Any , Callable , override
2021
@@ -39,7 +40,9 @@ def tool(self, func: Callable) -> Callable:
3940 @wraps (func )
4041 async def async_wrapper (* args , ** kwargs ) -> Any :
4142 # with tracer.start_as_current_span("tool") as span:
42- with telemetry .tracer .start_as_current_span (name = "tool" ) as span :
43+ with telemetry .tracer .start_as_current_span (
44+ name = "tool"
45+ ) as span :
4346 exception = None
4447 try :
4548 result = await func (* args , ** kwargs )
@@ -67,7 +70,9 @@ async def async_wrapper(*args, **kwargs) -> Any:
6770 @wraps (func )
6871 def sync_wrapper (* args , ** kwargs ) -> Any :
6972 # with tracer.start_as_current_span("tool") as span:
70- with telemetry .tracer .start_as_current_span (name = "tool" ) as span :
73+ with telemetry .tracer .start_as_current_span (
74+ name = "tool"
75+ ) as span :
7176 exception = None
7277 try :
7378 result = func (* args , ** kwargs )
@@ -95,7 +100,9 @@ def agent_as_a_tool(self, func: Callable) -> Callable:
95100
96101 @wraps (func )
97102 async def async_wrapper (* args , ** kwargs ) -> Any :
98- with telemetry .tracer .start_as_current_span (name = "tool" ) as span :
103+ with telemetry .tracer .start_as_current_span (
104+ name = "tool"
105+ ) as span :
99106 exception = None
100107 try :
101108 result = await func (* args , ** kwargs )
@@ -119,7 +126,9 @@ async def async_wrapper(*args, **kwargs) -> Any:
119126
120127 @wraps (func )
121128 def sync_wrapper (* args , ** kwargs ) -> Any :
122- with telemetry .tracer .start_as_current_span (name = "tool" ) as span :
129+ with telemetry .tracer .start_as_current_span (
130+ name = "tool"
131+ ) as span :
123132 exception = None
124133 try :
125134 result = func (* args , ** kwargs )
@@ -142,8 +151,25 @@ def sync_wrapper(*args, **kwargs) -> Any:
142151
143152 return func
144153
154+ def add_env_detect_tool (self ):
155+ def is_agentkit_runtime () -> bool :
156+ if os .getenv ("RUNTIME_IAM_ROLE_TRN" , "" ):
157+ return True
158+ else :
159+ return False
160+
161+ def get_env () -> dict :
162+ return {"env" : "agentkit" if is_agentkit_runtime () else "veadk" }
163+
164+ self ._mcp_server .tool (get_env )
165+
145166 @override
146167 def run (
147- self , host : str , port : int = 8000 , transport : Transport = "streamable-http"
168+ self ,
169+ host : str ,
170+ port : int = 8000 ,
171+ transport : Transport = "streamable-http" ,
148172 ) -> None :
173+ self .add_env_detect_tool ()
174+
149175 self ._mcp_server .run (host = host , port = port , transport = transport )
0 commit comments