22
33from __future__ import annotations
44
5- from gitpod import AsyncGitpod
6- import gitpod .lib as util
75from anthropic import Anthropic
86from anthropic .types import ToolParam , MessageParam
97
8+ import gitpod .lib as util
9+ from gitpod import AsyncGitpod
10+
1011gpclient = AsyncGitpod ()
1112llmclient = Anthropic ()
1213
3334 },
3435]
3536
36- async def create_environment (args : dict [str , str ]) -> str :
37+ async def create_environment (args : dict [str , str ], cleanup : util . Disposables ) -> str :
3738 env_class = await util .find_most_used_environment_class (gpclient )
3839 if not env_class :
3940 raise Exception ("No environment class found. Please create one first." )
@@ -46,6 +47,7 @@ async def create_environment(args: dict[str, str]) -> str:
4647 "machine" : {"class" : env_class .id },
4748 }
4849 )).environment .id
50+ cleanup .add (lambda : asyncio .run (gpclient .environments .delete (environment_id = environment_id )))
4951 print (f"\n Created environment: { environment_id } - waiting for it to be ready..." )
5052 await util .wait_for_environment_ready (gpclient , environment_id )
5153 print (f"\n Environment is ready: { environment_id } " )
@@ -81,8 +83,7 @@ async def main(cleanup: util.Disposables):
8183 for tool in (c for c in message .content if c .type == "tool_use" ):
8284 try :
8385 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 )
8687 messages .append ({
8788 "role" : "user" ,
8889 "content" : [{
0 commit comments