Skip to content
Open
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
20 changes: 16 additions & 4 deletions samples/python/agents/langgraph/app/test_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging

from typing import Any
Expand Down Expand Up @@ -125,7 +126,9 @@ async def main() -> None:
)

response = await client.send_message(request)
print(response.model_dump(mode='json', exclude_none=True))
print("=== Send Message Response ===")
print(json.dumps(response.model_dump(mode='json', exclude_none=True), indent=2))
print("=" * 50)
Comment on lines +129 to +131
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The code block for printing the response is repeated multiple times in this file (e.g., lines 153-155 and 176-178).

To improve maintainability and follow the DRY (Don't Repeat Yourself) principle, consider extracting this logic into a helper function.

# --8<-- [end:send_message]

# --8<-- [start:Multiturn]
Expand All @@ -147,7 +150,9 @@ async def main() -> None:
)

response = await client.send_message(request)
print(response.model_dump(mode='json', exclude_none=True))
print("=== Multi-turn First Response ===")
print(json.dumps(response.model_dump(mode='json', exclude_none=True), indent=2))
print("=" * 50)

task_id = response.root.result.id
context_id = response.root.result.context_id
Expand All @@ -168,7 +173,9 @@ async def main() -> None:
)

second_response = await client.send_message(second_request)
print(second_response.model_dump(mode='json', exclude_none=True))
print("=== Multi-turn Second Response ===")
print(json.dumps(second_response.model_dump(mode='json', exclude_none=True), indent=2))
print("=" * 50)
# --8<-- [end:Multiturn]

# --8<-- [start:send_message_streaming]
Expand All @@ -179,8 +186,13 @@ async def main() -> None:

stream_response = client.send_message_streaming(streaming_request)

print("=== Streaming Response Chunks ===")
chunk_count = 0
async for chunk in stream_response:
print(chunk.model_dump(mode='json', exclude_none=True))
chunk_count += 1
print(f"--- Chunk {chunk_count} ---")
print(json.dumps(chunk.model_dump(mode='json', exclude_none=True), indent=2))
print("=" * 50)
# --8<-- [end:send_message_streaming]


Expand Down