Quickstart Guide
Get started with Dialetica AI in minutes. Learn how to create a dialectical debate system where Thesis, Antithesis, and Synthesis agents engage in automatic philosophical reasoning.
Prerequisites
Before you begin, make sure you have:
- Python 3.8 or higher
- A Dialetica AI API key (get one from your dashboard)
1
Install the SDK
pip install dialetica
#or if using uv
#uv add dialetica2
Set Up Authentication
Get Your API Key
You can get your API key from the API Keys page in your dashboard.
Option 1: Environment Variable (Recommended)
export DIALETICA_AI_API_KEY="dai_your_api_key_here"Option 2: Pass Directly to Client
client = Dialetica(api_key="dai_your_api_key_here")3
Create Your Dialectical Triad
Thesis, Antithesis & Synthesis
Create three agents with different AI models (OpenAI, Claude, Gemini) for dialectical reasoning.
1from dialetica import Dialetica, AgentRequest
2
3# Initialize client
4client = Dialetica(api_key="dai_your_api_key_here")
5
6# Create three agents for dialectical debate using different providers
7thesis = client.agents.create(AgentRequest(
8 name="Thesis",
9 description="Proposes and defends initial positions",
10 instructions=["You present the initial argument (thesis). Be bold and assertive."],
11 model="auto/auto",
12 temperature=0.7,
13 max_tokens=500,
14 verbosity="medium"
15))
16
17antithesis = client.agents.create(AgentRequest(
18 name="Antithesis",
19 description="Challenges and opposes the thesis",
20 instructions=["You counter the thesis with opposing views (antithesis). Be critical and thorough."],
21 model="anthropic/claude-3-5-sonnet-20241022",
22 temperature=0.8,
23 max_tokens=500,
24 verbosity="high"
25))
26
27synthesis = client.agents.create(AgentRequest(
28 name="Synthesis",
29 description="Finds middle ground and higher truth",
30 instructions=["You synthesize thesis and antithesis into higher understanding. Find common ground."],
31 model="google/gemini-2.0-flash-exp:free",
32 temperature=0.6,
33 max_tokens=600,
34 verbosity="medium"
35))
36
37print(f"β
Created dialectical triad:")
38print(f" Thesis: {thesis.id}")
39print(f" Antithesis: {antithesis.id}")
40print(f" Synthesis: {synthesis.id}")4
Create Dialectical Context & Start Debate
Multi-Agent Automatic Debate
Create a context where all three agents automatically engage in dialectical reasoning. One API call triggers the entire debate!
1from dialetica import ContextRequest, MessageRequest
2
3# Create a dialectical context with all three agents
4context = client.contexts.create(ContextRequest(
5 name="Dialectical Debate",
6 description="Three agents engage in dialectical reasoning",
7 instructions=["Thesis proposes, Antithesis opposes, Synthesis reconciles"],
8 agents=[thesis.id, antithesis.id, synthesis.id],
9 context_window_size=8000,
10 is_public=False
11))
12
13# Send a question - agents will automatically debate!
14messages = [MessageRequest(
15 role="user",
16 sender_name="Philosopher",
17 content="Is artificial intelligence a threat or opportunity for humanity?"
18)]
19
20# ONE API CALL triggers the entire dialectical process
21responses = client.contexts.run(context.id, messages)
22
23print(f"π Dialectical debate complete! {len(responses)} exchanges")
24for response in responses:
25 print(f"\n{response.sender_name}: {response.content[:100]}...")5
Stream the Debate (Optional)
Real-time Dialectical Streaming
Watch the dialectical process unfold in real-time as Thesis, Antithesis, and Synthesis respond to each other. The new event structure includes session management and detailed event types.
1# Stream the dialectical debate in real-time
2import asyncio
3
4async def stream_debate():
5 messages = [MessageRequest(
6 role="user",
7 sender_name="Philosopher",
8 content="Should we pursue immortality through technology?"
9 )]
10
11 session_id = None
12
13 async for event in client.contexts.run_streamed(context.id, messages):
14 event_type = event.get('type')
15 payload = event.get('payload', {})
16
17 # Capture session_id when session starts
18 if event_type == 'session_started':
19 session_id = payload.get('session_id')
20 print(f"\n㪠Session started: {session_id}\n")
21
22 # Stream token-by-token content
23 elif event_type == 'token_delta' and payload.get('kind') == 'agent':
24 print(payload.get('delta', ''), end='', flush=True)
25
26 # Agent turn completed
27 elif event_type == 'turn_completed' and payload.get('kind') == 'agent':
28 print(f"\nβ
{payload.get('runnable_name')} completed\n")
29
30 # Session completed or failed
31 elif event_type == 'session_completed':
32 print(f"\nπ Session completed successfully!")
33 elif event_type == 'session_failed':
34 print(f"\nβ Session failed: {payload.get('reason')}")
35
36 return session_id
37
38# Run the stream
39session_id = asyncio.run(stream_debate())
40
41# You can cancel a session if needed
42# client.contexts.cancel_session(context.id, session_id)6
Discover Available Models
List AI Models
Get a list of all available AI models with their tiers (free/pro) to choose the best model for your agents.
1# List available AI models
2from dialetica import Dialetica
3
4client = Dialetica(api_key="dai_your_api_key_here")
5
6# Get all available models
7models = client.models.list()
8
9print("Available AI Models:")
10print("=" * 60)
11for model in models:
12 tier_badge = "π FREE" if model['tier'] == 'free' else "π PRO"
13 print(f"{tier_badge} {model['label']}")
14 print(f" Model ID: {model['model']}")
15 print()
16
17# Filter by tier
18free_models = [m for m in models if m['tier'] == 'free']
19pro_models = [m for m in models if m['tier'] == 'pro']
20
21print(f"\nFree models: {len(free_models)}")
22print(f"Pro models: {len(pro_models)}")7
Session Management (Advanced)
Cancel and Monitor Sessions
Control running sessions by cancelling them or listing active sessions. Useful for long-running operations or user-initiated stops.
1# Session Management - Cancel and Monitor Sessions
2import asyncio
3from dialetica import Dialetica, MessageRequest
4
5client = Dialetica(api_key="dai_your_api_key_here")
6
7async def manage_session_example():
8 context_id = "your-context-id"
9 messages = [MessageRequest(
10 role="user",
11 sender_name="User",
12 content="Explain quantum mechanics in detail"
13 )]
14
15 session_id = None
16
17 # Start streaming session
18 async for event in client.contexts.run_streamed(context_id, messages):
19 event_type = event.get('type')
20 payload = event.get('payload', {})
21
22 if event_type == 'session_started':
23 session_id = payload.get('session_id')
24 print(f"Session started: {session_id}")
25
26 # Cancel after 5 seconds (example)
27 # In real usage, you'd cancel based on user action
28 if session_id and event_type == 'token_delta':
29 # Example: cancel if user wants to stop
30 # client.contexts.cancel_session(context_id, session_id)
31 pass
32
33 # List all active sessions for a context
34 active_sessions = client.contexts.list_sessions(context_id)
35 print(f"\nActive sessions: {len(active_sessions)}")
36 for session in active_sessions:
37 print(f" - {session['session_id']} (depth: {session['depth']})")
38
39asyncio.run(manage_session_example())Next Steps
Continue learning with these resources:
Need Help?
If you run into any issues or have questions, reach out to our support team.