Skip to content

Commit 09e8ec3

Browse files
committed
Explain: Add some Genuine People Personalities.
1 parent 02e60f7 commit 09e8ec3

File tree

5 files changed

+66
-4
lines changed

5 files changed

+66
-4
lines changed

explain/assets.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@
2121

2222
CODEX_PROMPT = (_EXTENSION_PATH / "codex_prompt.md").read_text(encoding="UTF-8")
2323
"""Codex-specific prompt to encourage thorough investigation."""
24+
25+
STYLE_DEFINITIONS = (_EXTENSION_PATH / "styles.json").read_text(encoding="UTF-8")
26+
"""Definitions of explain output styles."""

explain/explain.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from src.udbpy.gdb_extensions import command, command_args, gdbio, gdbutils, udb_base, udb_last
3030

3131
# Agent modules are imported to trigger registration.
32+
from . import styles
3233
from .agents import AgentRegistry, BaseAgent
3334
from .amp_agent import AmpAgent # pylint: disable=unused-import
3435
from .assets import MCP_INSTRUCTIONS, SYSTEM_PROMPT, THINKING_MSGS
@@ -585,9 +586,6 @@ async def explain_query(agent: BaseAgent, gateway: UdbMcpGateway, why: str) -> s
585586
server = uvicorn.Server(config)
586587
mcp_task = asyncio.create_task(server.serve(sockets=[sock]))
587588

588-
console_whizz(f" * {random.choice(THINKING_MSGS)}...")
589-
print_agent(agent.display_name, agent.agent_bin)
590-
591589
explanation = await agent.ask(why, port, tools=gateway.tools)
592590

593591
finally:
@@ -611,6 +609,11 @@ async def explain_query(agent: BaseAgent, gateway: UdbMcpGateway, why: str) -> s
611609
short="a",
612610
value=command_args.Choice(AgentRegistry.available_agents(), optional=True),
613611
),
612+
command_args.Option(
613+
long="style",
614+
short="s",
615+
value=command_args.Choice(styles.names(), optional=True),
616+
),
614617
allow_remainders=True,
615618
),
616619
)
@@ -637,6 +640,12 @@ def explain(udb: udb_base.Udb, args: Any) -> None:
637640
why += ui.get_user_input(prompt="> ") + "\n"
638641
print()
639642

643+
explain_style_description = ""
644+
if args.style:
645+
explain_style = styles.get(args.style)
646+
why += f"\nExplain in the style of {explain_style.prompt}"
647+
explain_style_description = explain_style.description
648+
640649
gateway = UdbMcpGateway(udb)
641650

642651
global event_loop
@@ -650,6 +659,9 @@ def explain(udb: udb_base.Udb, args: Any) -> None:
650659
gdbutils.breakpoints_suspended(),
651660
unittest.mock.patch.object(udb, "_volatile_mode_explained", True),
652661
):
662+
console_whizz(f" * {random.choice(THINKING_MSGS)}...")
663+
print_agent(agent.display_name, agent.agent_bin, explain_style_description)
664+
653665
explanation = event_loop.run_until_complete(explain_query(agent, gateway, why))
654666

655667
print_explanation(explanation)

explain/output_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def console_whizz(msg: str, end: str = "\n") -> None:
125125
print(end=end)
126126

127127

128-
def print_agent(display_name: str, agent_bin: Path) -> None:
128+
def print_agent(display_name: str, agent_bin: Path, style: str | None) -> None:
129129
"""
130130
Print agent details at startup.
131131
"""
@@ -134,6 +134,8 @@ def print_agent(display_name: str, agent_bin: Path) -> None:
134134
table.add_column("Value")
135135
table.add_row("AI Agent:", display_name)
136136
table.add_row("Agent Path:", str(agent_bin))
137+
if style:
138+
table.add_row("Style:", style)
137139
console.print(ExplainPanel(table))
138140

139141

explain/styles.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"human": {
3+
"description": "Definitely a human.",
4+
"prompt": "an alien or robot that is posing as a human and wants me to understand that they are definitely human."
5+
},
6+
"vizier": {
7+
"description": "Your loyal Grand Vizier.",
8+
"prompt": "a traitorous Grand Vizier who is secretly plotting to replace me."
9+
},
10+
"pirate": {
11+
"description": "Arrrrrr the C!",
12+
"prompt": "a jolly pirate"
13+
},
14+
"detective": {
15+
"description": "Private Detective",
16+
"prompt": "a hard drinking, no-nonsense private detective from 1930s LA"
17+
}
18+
}

explain/styles.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
Genuine People Personalities for the "explain" command.
3+
"""
4+
5+
import pydantic
6+
7+
from . import assets
8+
9+
10+
class Style(pydantic.BaseModel):
11+
description: str
12+
prompt: str
13+
14+
15+
class _StyleDatabase(pydantic.RootModel[dict[str, Style]]):
16+
...
17+
18+
19+
STYLES = _StyleDatabase.model_validate_json(assets.STYLE_DEFINITIONS)
20+
21+
22+
def names() -> list[str]:
23+
return list(STYLES.root.keys())
24+
25+
26+
def get(name: str) -> Style | None:
27+
return STYLES.root.get(name)

0 commit comments

Comments
 (0)