forked from nicknochnack/ACPWalkthrough
-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathhelpers.py
More file actions
57 lines (47 loc) · 1.8 KB
/
helpers.py
File metadata and controls
57 lines (47 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import warnings
import nest_asyncio
from IPython.display import Markdown, display
from a2a.types import AgentCard
from dotenv import load_dotenv
def setup_env() -> None:
"""Initializes the environment by loading .env and applying nest_asyncio."""
load_dotenv(override=True)
nest_asyncio.apply()
warnings.filterwarnings("ignore", category=UserWarning)
warnings.filterwarnings("ignore", category=FutureWarning)
def display_agent_card(agent_card: AgentCard) -> None:
"""Nicely formats and displays an AgentCard."""
def esc(text: str) -> str:
"""Escapes pipe characters for Markdown table compatibility."""
return str(text).replace("|", r"\|")
# --- Part 1: Main Metadata Table ---
md_parts = [
"### Agent Card Details",
"| Property | Value |",
"| :--- | :--- |",
f"| **Name** | {esc(agent_card.name)} |",
f"| **Description** | {esc(agent_card.description)} |",
f"| **Version** | `{esc(agent_card.version)}` |",
f"| **URL** | [{esc(agent_card.url)}]({agent_card.url}) |",
f"| **Protocol Version** | `{esc(agent_card.protocol_version)}` |",
]
# --- Part 2: Skills Table ---
if agent_card.skills:
md_parts.extend(
[
"\n#### Skills",
"| Name | Description | Examples |",
"| :--- | :--- | :--- |",
]
)
for skill in agent_card.skills:
examples_str = (
"<br>".join(f"• {esc(ex)}" for ex in skill.examples)
if skill.examples
else "N/A"
)
md_parts.append(
f"| **{esc(skill.name)}** | {esc(skill.description)} | {examples_str} |"
)
# Join all parts and display
display(Markdown("\n".join(md_parts)))