11import abc
22import contextlib
33import logging
4+ import uuid
45from abc import ABC
56from json import JSONDecodeError
67from typing import Any , Dict , List , Optional , Type , Union , cast
@@ -142,6 +143,7 @@ def run(self):
142143class AgentREPL (SteamshipREPL ):
143144 agent_class : Type [AgentService ]
144145 agent_instance : Optional [AgentService ]
146+ context_id : Optional [str ] = None
145147 client = Steamship
146148 config = None
147149
@@ -151,6 +153,7 @@ def __init__(
151153 method : Optional [str ] = None ,
152154 agent_package_config : Optional [Dict [str , Any ]] = None ,
153155 client : Optional [Steamship ] = None ,
156+ context_id : Optional [str ] = None ,
154157 ** kwargs ,
155158 ):
156159 super ().__init__ (** kwargs )
@@ -159,6 +162,7 @@ def __init__(
159162 self .client = client or Steamship ()
160163 self .config = agent_package_config
161164 self .agent_instance = None
165+ self .context_id = context_id or uuid .uuid4 ()
162166
163167 def run_with_client (self , client : Steamship , ** kwargs ):
164168 try :
@@ -178,7 +182,7 @@ def colored(text: str, color: str, **kwargs):
178182
179183 while True :
180184 input_text = input (colored (text = "Input: " , color = "blue" )) # noqa: F821
181- output = responder (input_text )
185+ output = responder (prompt = input_text , context_id = self . context_id )
182186 self .print_object_or_objects (output )
183187
184188 def run (self , ** kwargs ):
@@ -192,11 +196,19 @@ class HttpREPL(SteamshipREPL):
192196 prompt_url : Optional [AgentService ]
193197 client = Steamship
194198 config = None
199+ context_id : Optional [str ] = None
195200
196- def __init__ (self , prompt_url : str , client : Optional [Steamship ] = None , ** kwargs ):
201+ def __init__ (
202+ self ,
203+ prompt_url : str ,
204+ context_id : Optional [str ] = None ,
205+ client : Optional [Steamship ] = None ,
206+ ** kwargs ,
207+ ):
197208 super ().__init__ (** kwargs )
198209 self .prompt_url = prompt_url
199210 self .client = client or Steamship ()
211+ self .context_id = context_id or uuid .uuid4 ()
200212
201213 def run_with_client (self , client : Steamship , ** kwargs ): # noqa: C901
202214 try :
@@ -212,7 +224,7 @@ def colored(text: str, color: str):
212224 input_text = input (colored (text = "Input: " , color = "blue" )) # noqa: F821
213225 resp = requests .post (
214226 self .prompt_url ,
215- json = {"prompt" : input_text },
227+ json = {"prompt" : input_text , "context_id" : self . context_id },
216228 headers = {
217229 "Content-Type" : "application/json" ,
218230 "Authorization" : f"Bearer { self .client .config .api_key .get_secret_value ()} " ,
0 commit comments