Skip to content
Open
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
645 changes: 572 additions & 73 deletions notebooks/agent.ipynb

Large diffs are not rendered by default.

585 changes: 528 additions & 57 deletions notebooks/evaluation.ipynb

Large diffs are not rendered by default.

1,516 changes: 1,442 additions & 74 deletions notebooks/hitl.ipynb

Large diffs are not rendered by default.

1,167 changes: 1,091 additions & 76 deletions notebooks/langgraph_101.ipynb

Large diffs are not rendered by default.

2,217 changes: 1,927 additions & 290 deletions notebooks/memory.ipynb

Large diffs are not rendered by default.

81 changes: 81 additions & 0 deletions notebooks/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from rich.console import Console
from rich.panel import Panel
from rich.text import Text
import json

console = Console()

def format_message_content(message):
"""Convert message content to displayable string"""
parts = []
tool_calls_processed = False

# Handle main content
if isinstance(message.content, str):
parts.append(message.content)
elif isinstance(message.content, list):
# Handle complex content like tool calls (Anthropic format)
for item in message.content:
if item.get('type') == 'text':
parts.append(item['text'])
elif item.get('type') == 'tool_use':
parts.append(f"\n🔧 Tool Call: {item['name']}")
parts.append(f" Args: {json.dumps(item['input'], indent=2)}")
parts.append(f" ID: {item.get('id', 'N/A')}")
tool_calls_processed = True
else:
parts.append(str(message.content))

# Handle tool calls attached to the message (OpenAI format) - only if not already processed
if not tool_calls_processed and hasattr(message, 'tool_calls') and message.tool_calls:
for tool_call in message.tool_calls:
parts.append(f"\n🔧 Tool Call: {tool_call['name']}")
parts.append(f" Args: {json.dumps(tool_call['args'], indent=2)}")
parts.append(f" ID: {tool_call['id']}")

return "\n".join(parts)


def format_messages(messages):
"""Format and display a list of messages with Rich formatting"""
for m in messages:
msg_type = m.__class__.__name__.replace('Message', '')
content = format_message_content(m)

if msg_type == 'Human':
console.print(Panel(content, title="🧑 Human", border_style="blue"))
elif msg_type == 'Ai':
console.print(Panel(content, title="🤖 Assistant", border_style="green"))
elif msg_type == 'Tool':
console.print(Panel(content, title="🔧 Tool Output", border_style="yellow"))
else:
console.print(Panel(content, title=f"📝 {msg_type}", border_style="white"))


def format_message(messages):
"""Alias for format_messages for backward compatibility"""
return format_messages(messages)


def show_prompt(prompt_text: str, title: str = "Prompt", border_style: str = "blue"):
"""
Display a prompt with rich formatting and XML tag highlighting.

Args:
prompt_text: The prompt string to display
title: Title for the panel (default: "Prompt")
border_style: Border color style (default: "blue")
"""
# Create a formatted display of the prompt
formatted_text = Text(prompt_text)
formatted_text.highlight_regex(r'<[^>]+>', style="bold blue") # Highlight XML tags
formatted_text.highlight_regex(r'##[^#\n]+', style="bold magenta") # Highlight headers
formatted_text.highlight_regex(r'###[^#\n]+', style="bold cyan") # Highlight sub-headers

# Display in a panel for better presentation
console.print(Panel(
formatted_text,
title=f"[bold green]{title}[/bold green]",
border_style=border_style,
padding=(1, 2)
))
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ requires-python = ">=3.11"
dependencies = [
"langchain>=0.3.9",
"langchain-core>=0.3.59",
"langchain-openai",
"langchain-openai>=0.3.30",
"openai>=1.100.1",
"langgraph>=0.4.2",
"langsmith[pytest]>=0.3.4",
"pandas",
Expand Down
39 changes: 22 additions & 17 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.