Skip to content

Commit 94a3c66

Browse files
authored
Logging prints (#37)
* fix: function url curls with body data * fix: logging prints * fix: more log statements
1 parent 0934e05 commit 94a3c66

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

index.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@ def handler(event, context):
99
Lambda handler function
1010
"""
1111
# Log the input event for debugging purposes
12-
print("Received event:", json.dumps(event, indent=2))
12+
# print("Received event:", " ".join(json.dumps(event, indent=2).splitlines()))
13+
14+
if "body" in event:
15+
try:
16+
event = json.loads(event["body"])
17+
except json.JSONDecodeError:
18+
return {
19+
"statusCode": 400,
20+
"body": "Invalid JSON format in the body. Please check the input."
21+
}
1322

1423
if "message" not in event:
1524
return {
@@ -40,6 +49,6 @@ def handler(event, context):
4049
}
4150

4251
# Log the response for debugging purposes
43-
print("Returning response:", json.dumps(response, indent=2))
52+
print("Returning response:", " ".join(json.dumps(response, indent=2).splitlines()))
4453

4554
return response

src/agents/informational_agent/informational_agent.py

+6
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ def call_model(self, state: State, config: RunnableConfig) -> str:
7979
messages = [SystemMessage(content=system_message)] + state['messages']
8080

8181
valid_messages = self.check_for_valid_messages(messages)
82+
print("Informational agent valid messages, ready for LLM call...")
8283
response = self.llm.invoke(valid_messages)
84+
print("Informational agent response successfully received.")
8385

8486
# Save summary for fetching outside the class
8587
self.summary = summary
@@ -131,6 +133,7 @@ def summarize_conversation(self, state: State, config: RunnableConfig) -> dict:
131133
valid_messages = self.check_for_valid_messages(messages)
132134
conversationalStyle_response = self.summarisation_llm.invoke(valid_messages)
133135

136+
print("Informational agent summary and conversational style responses successfully received.")
134137
# Delete messages that are no longer wanted, except the last ones
135138
delete_messages: list[AllMessageTypes] = [RemoveMessage(id=m.id) for m in state["messages"][:-3]]
136139

@@ -153,6 +156,7 @@ def should_summarize(self, state: State) -> str:
153156

154157
# always pairs of (sent, response) + 1 latest message
155158
if nr_messages > self.max_messages_to_summarize:
159+
print("Informational agent: summarizing conversation needed...")
156160
return "summarize_conversation"
157161
return "call_llm"
158162

@@ -185,7 +189,9 @@ def invoke_informational_agent(query: str, conversation_history: list, summary:
185189
print(f'in invoke_informational_agent(), thread_id = {session_id}')
186190

187191
config = {"configurable": {"thread_id": session_id, "summary": summary, "conversational_style": conversationalStyle, "question_response_details": question_response_details}}
192+
print("Informational agent invoking...")
188193
response_events = agent.app.invoke({"messages": conversation_history, "summary": summary, "conversational_style": conversationalStyle}, config=config, stream_mode="values") #updates
194+
print("Informational agent response received.")
189195
pretty_printed_response = agent.pretty_response_value(response_events) # get last event/ai answer in the response
190196

191197
# Gather Metadata from the agent

src/module.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ def chat_module(message: Any, params: Params) -> Result:
6363
question_information,
6464
question_access_information
6565
)
66-
print("INFO:: ", question_response_details_prompt)
66+
print("INFO:: ", " ".join(question_response_details_prompt.splitlines()))
6767
except Exception as e:
68-
print("ERROR:: ", e)
68+
print("ERROR on parsing the JSON event to prompt:: ", e)
6969
raise Exception("Internal Error: The question response details could not be parsed.")
7070
if "agent_type" in params:
7171
agent_type = params["agent_type"]

0 commit comments

Comments
 (0)