Skip to content

Logging prints #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions index.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ def handler(event, context):
Lambda handler function
"""
# Log the input event for debugging purposes
print("Received event:", json.dumps(event, indent=2))
# print("Received event:", " ".join(json.dumps(event, indent=2).splitlines()))

if "body" in event:
try:
event = json.loads(event["body"])
except json.JSONDecodeError:
return {
"statusCode": 400,
"body": "Invalid JSON format in the body. Please check the input."
}

if "message" not in event:
return {
Expand Down Expand Up @@ -40,6 +49,6 @@ def handler(event, context):
}

# Log the response for debugging purposes
print("Returning response:", json.dumps(response, indent=2))
print("Returning response:", " ".join(json.dumps(response, indent=2).splitlines()))

return response
6 changes: 6 additions & 0 deletions src/agents/informational_agent/informational_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ def call_model(self, state: State, config: RunnableConfig) -> str:
messages = [SystemMessage(content=system_message)] + state['messages']

valid_messages = self.check_for_valid_messages(messages)
print("Informational agent valid messages, ready for LLM call...")
response = self.llm.invoke(valid_messages)
print("Informational agent response successfully received.")

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

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

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

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

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

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

# Gather Metadata from the agent
Expand Down
4 changes: 2 additions & 2 deletions src/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def chat_module(message: Any, params: Params) -> Result:
question_information,
question_access_information
)
print("INFO:: ", question_response_details_prompt)
print("INFO:: ", " ".join(question_response_details_prompt.splitlines()))
except Exception as e:
print("ERROR:: ", e)
print("ERROR on parsing the JSON event to prompt:: ", e)
raise Exception("Internal Error: The question response details could not be parsed.")
if "agent_type" in params:
agent_type = params["agent_type"]
Expand Down