Two Speaker Conversation

Source: examples/patterns/two_speaker_conversation.py

Introduction

AutoGen-style multi-agent conversations can externalize reasoning roles, Human-AI collaboration by design explains why role separation matters for oversight, and AI-assisted design synthesis work motivates structured dialogue in design ideation. This example implements a two-agent conversation loop with trace visibility at each turn.

Technical Implementation

  1. Configure Tracer with JSONL + console output so each run emits machine-readable traces and lifecycle logs.

  2. Build the runtime surface (public APIs only) and execute TwoSpeakerConversationPattern.run(...) with a fixed request_id.

  3. Capture structured outputs from runtime execution and preserve termination metadata for analysis.

  4. Print a compact JSON payload including trace_info for deterministic tests and docs examples.

        flowchart LR
    A["Input prompt or scenario"] --> B["main(): runtime wiring"]
    B --> C["TwoSpeakerConversationPattern.run(...)"]
    C --> D["turn-based conversation state drives each step"]
    C --> E["Tracer JSONL + console events"]
    D --> F["ExecutionResult/payload"]
    E --> F
    F --> G["Printed JSON output"]
    
 1from __future__ import annotations
 2
 3import json
 4from pathlib import Path
 5
 6from design_research_agents import LlamaCppServerLLMClient, Tracer
 7from design_research_agents.patterns import TwoSpeakerConversationPattern
 8
 9
10def main() -> None:
11    """Run two-speaker brainstorming loop for a serviceable device enclosure."""
12    # Fixed request id keeps traces and docs output deterministic across runs.
13    request_id = "example-workflow-two-speaker-conversation-design-001"
14    tracer = Tracer(
15        enabled=True,
16        trace_dir=Path("artifacts/examples/traces"),
17        enable_jsonl=True,
18        enable_console=True,
19    )
20    # Run the two-speaker conversation using the managed local client. Using this with statement will
21    # automatically shut down the client when the example is done.
22    with LlamaCppServerLLMClient() as llm_client:
23        pattern = TwoSpeakerConversationPattern(
24            llm_client_a=llm_client,
25            max_turns=5,
26            speaker_a_name="Concept Designer",
27            speaker_b_name="Validation Engineer",
28            speaker_a_system_prompt=(
29                "You are Concept Designer. Propose practical ideas for a field-serviceable sensor enclosure."
30            ),
31            speaker_b_system_prompt=(
32                "You are Validation Engineer. Stress-test ideas for manufacturability, safety, and maintenance time."
33            ),
34            tracer=tracer,
35        )
36        result = pattern.run(
37            prompt=(
38                "Brainstorm a modular enclosure for a wearable biosensor. Cover sealing strategy, "
39                "fastener choices, and quick battery replacement."
40            ),
41            request_id=request_id,
42        )
43
44    # Print the results
45    summary = result.summary()
46    print(json.dumps(summary, ensure_ascii=True, indent=2, sort_keys=True))
47
48
49if __name__ == "__main__":
50    main()

Expected Results

Run Command

PYTHONPATH=src python3 examples/patterns/two_speaker_conversation.py

Example output shape (values vary by run):

{
  "success": true,
  "final_output": "<example-specific payload>",
  "terminated_reason": "<string-or-null>",
  "error": null,
  "trace": {
    "request_id": "<request-id>",
    "trace_dir": "artifacts/examples/traces",
    "trace_path": "artifacts/examples/traces/run_<timestamp>_<request_id>.jsonl"
  }
}

References