Skip to content

Commit 0d18028

Browse files
committed
try again
1 parent 27e3bb4 commit 0d18028

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/routine_discovery/agent.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from src.data_models.dev_routine import Routine, RoutineFetchOperation
2727
from src.utils.exceptions import TransactionIdentificationFailedError
2828

29-
logging.basicConfig(level=logging.DEBUG)
29+
logging.basicConfig(level=logging.INFO)
3030
logger = logging.getLogger(__name__)
3131

3232

@@ -81,28 +81,37 @@ def run(self) -> None:
8181
self._add_to_message_history("user", f"These are the possible network transaction ids you can choose from: {self.context_manager.get_all_transaction_ids()}")
8282

8383
logger.info("Identifying the network transaction that directly corresponds to the user's requested task...")
84-
logger.debug(f"\n\nMessage history:\n{self.message_history}\n\n")
84+
logger.info(f"\n\nMessage history:\n{self.message_history}\n\n")##DEBUG
8585

8686
identified_transaction = None
8787
while identified_transaction is None:
8888
# identify the transaction
8989
identified_transaction = self.identify_transaction()
90+
logger.info(f"\nIdentified transaction:\n{identified_transaction.model_dump_json()}")##DEBUG
9091

9192
if identified_transaction.transaction_id is None:
9293
logger.error("Failed to identify the network transactions that directly correspond to the user's requested task.")
9394
raise Exception("Failed to identify the network transactions that directly correspond to the user's requested task.")
9495

9596
# confirm the identified transaction
9697
confirmation_response = self.confirm_identified_transaction(identified_transaction)
97-
98+
logger.info(f"\nConfirmation response:\n{confirmation_response.model_dump_json()}")##DEBUG
99+
98100
# if the identified transaction is not correct, try again
99101
if not confirmation_response.is_correct:
100102
identified_transaction = None
101103
self.current_transaction_identification_attempt += 1
102-
104+
logger.info(
105+
"Trying again to identify the network transaction that directly corresponds to the user's requested task... "
106+
f"(attempt {self.current_transaction_identification_attempt})"
107+
)##DEBUG
108+
103109
if identified_transaction is None:
104110
logger.error("Failed to identify the network transactions that directly correspond to the user's requested task.")
105-
raise TransactionIdentificationFailedError("Failed to identify the network transactions that directly correspond to the user's requested task.")
111+
raise TransactionIdentificationFailedError(
112+
"Failed to identify the network transactions that directly correspond to the user's requested task."
113+
)
114+
logger.info(f"Identified transaction: {identified_transaction.transaction_id}")##DEBUG
106115

107116
# save the indentified transactions
108117
save_path = os.path.join(self.output_dir, "root_transaction.json")
@@ -195,6 +204,8 @@ def run(self) -> None:
195204
def identify_transaction(self) -> TransactionIdentificationResponse:
196205
"""
197206
Identify the network transactions that directly correspond to the user's requested task.
207+
Returns:
208+
TransactionIdentificationResponse: The response from the LLM API.
198209
"""
199210
if self.current_transaction_identification_attempt == 0:
200211
self.message_history = [
@@ -221,6 +232,8 @@ def identify_transaction(self) -> TransactionIdentificationResponse:
221232
f"Respond in the following format: {TransactionIdentificationResponse.model_json_schema()}"
222233
)
223234
self._add_to_message_history("user", message)
235+
236+
logger.info(f"\n\nMessage history:\n{self.message_history}\n")##DEBUG
224237

225238
# call to the LLM API
226239
response = self.client.responses.create(
@@ -233,10 +246,12 @@ def identify_transaction(self) -> TransactionIdentificationResponse:
233246

234247
# save the response id
235248
self.last_response_id = response.id
236-
249+
237250
# collect the text from the response
238251
response_text = collect_text_from_response(response)
239252
self._add_to_message_history("assistant", response_text)
253+
254+
logger.info(f"\nResponse text:\n{response_text}\n\n")##DEBUG
240255

241256
# TODO FIXME BUG
242257
# parse the response to the pydantic model
@@ -248,6 +263,9 @@ def identify_transaction(self) -> TransactionIdentificationResponse:
248263
llm_model='gpt-5-nano'
249264
)
250265
self._add_to_message_history("assistant", parsed_response.model_dump_json())
266+
267+
logger.info(f"\nParsed response:\n{parsed_response.model_dump_json()}")##DEBUG
268+
logger.info(f"New chat history:\n{self.message_history}\n")##DEBUG
251269

252270
# return the parsed response
253271
return parsed_response

0 commit comments

Comments
 (0)