2
2
3
3
from __future__ import annotations
4
4
5
- from gitpod import AsyncGitpod
6
- import gitpod .lib as util
7
5
from anthropic import Anthropic
8
6
from anthropic .types import ToolParam , MessageParam
9
7
8
+ import gitpod .lib as util
9
+ from gitpod import AsyncGitpod
10
+
10
11
gpclient = AsyncGitpod ()
11
12
llmclient = Anthropic ()
12
13
33
34
},
34
35
]
35
36
36
- async def create_environment (args : dict [str , str ]) -> str :
37
+ async def create_environment (args : dict [str , str ], cleanup : util . Disposables ) -> str :
37
38
env_class = await util .find_most_used_environment_class (gpclient )
38
39
if not env_class :
39
40
raise Exception ("No environment class found. Please create one first." )
@@ -46,6 +47,7 @@ async def create_environment(args: dict[str, str]) -> str:
46
47
"machine" : {"class" : env_class .id },
47
48
}
48
49
)).environment .id
50
+ cleanup .add (lambda : asyncio .run (gpclient .environments .delete (environment_id = environment_id )))
49
51
print (f"\n Created environment: { environment_id } - waiting for it to be ready..." )
50
52
await util .wait_for_environment_ready (gpclient , environment_id )
51
53
print (f"\n Environment is ready: { environment_id } " )
@@ -81,8 +83,7 @@ async def main(cleanup: util.Disposables):
81
83
for tool in (c for c in message .content if c .type == "tool_use" ):
82
84
try :
83
85
if tool .name == "create_environment" :
84
- environment_id = await create_environment (tool .input )
85
- cleanup .add (lambda : asyncio .run (gpclient .environments .delete (environment_id = environment_id )))
86
+ environment_id = await create_environment (tool .input , cleanup )
86
87
messages .append ({
87
88
"role" : "user" ,
88
89
"content" : [{
0 commit comments