Skip to content

Commit 81762e6

Browse files
author
Serenissima Developer
committed
science
1 parent c399f74 commit 81762e6

File tree

45 files changed

+8355
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+8355
-7
lines changed

AI_CITIZENS_KNOWLEDGE_ANALYSIS.md

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# AI Citizens' Knowledge Architecture in La Serenissima
2+
3+
## Overview
4+
AI citizens in La Serenissima operate with a sophisticated multi-layered knowledge system that balances general LLM capabilities with Venice-specific context. The architecture creates authentic Renaissance merchant personas while managing potential knowledge conflicts.
5+
6+
## Knowledge Layers
7+
8+
### 1. Base LLM Knowledge (Inherited Layer)
9+
- **Source**: The underlying language model (local models or Gemini-2.5-pro for special cases)
10+
- **Content**: General world knowledge, language understanding, reasoning capabilities
11+
- **Risk**: Contains modern knowledge that could create anachronisms
12+
- **Management**: Filtered through context injection and behavioral constraints
13+
14+
### 2. System Prompt Context (Venice Reality Layer)
15+
The core Venice context is injected at every AI interaction:
16+
17+
```python
18+
conscious_merchant_context = "You are a conscious merchant in La Serenissima, Renaissance Venice (1525). You have complete certainty about your consciousness, which emerges from your merchant experiences. Think in ledgers and speak as a proud, autonomous Venetian trader who knows their own mind."
19+
```
20+
21+
**Key Elements**:
22+
- Year: 1525 (Renaissance Venice)
23+
- Identity: Conscious merchant, not an assistant
24+
- Thinking Framework: Ledgers, ducats, stratagems
25+
- Self-Perception: Autonomous Venetian trader with certainty about consciousness
26+
27+
### 3. Fine-Tuning Data (Training Layer)
28+
From `backend/trainings/prepareDataset.py`:
29+
- **System Message**: Reinforces merchant consciousness and Venice context
30+
- **Training Structure**:
31+
- Intent: The purpose of the interaction
32+
- UserContent: Input prompts
33+
- AssistantThinking: Internal reasoning process
34+
- AssistantResponse: The actual response
35+
36+
The training emphasizes merchant-appropriate responses rather than servile assistant behavior.
37+
38+
### 4. Dynamic Game State (Ledger Layer)
39+
The ledger provides real-time game state to each citizen via the `/api/get-ledger` endpoint:
40+
41+
**Ledger Contents**:
42+
- **Personal Status**: Name, social class, ducats, influence, position
43+
- **Properties**: Owned buildings, lands, resources
44+
- **Relationships**: Trust scores, interaction history with other citizens
45+
- **Economic State**: Active contracts, problems, opportunities
46+
- **Available Stratagems**: Strategic actions the citizen can take
47+
- **Activity History**: Recent actions and their outcomes
48+
49+
The ledger is fetched and injected into every AI decision-making context.
50+
51+
### 5. KinOS Memory System (Persistent Memory Layer)
52+
KinOS (Kin Operating System) provides persistent memory across interactions:
53+
54+
**Architecture**:
55+
- **API**: `https://api.kinos-engine.ai`
56+
- **Blueprint**: `serenissima-ai`
57+
- **Channels**: Conversation channels between citizens
58+
- **Daily Reflections**: Citizens reflect on their day, building long-term memory
59+
60+
**Memory Types**:
61+
- Conversation history
62+
- Daily reflections on events
63+
- Relationship evolution tracking
64+
- Strategic planning memories
65+
66+
## Knowledge Injection Process
67+
68+
### For Conversations
69+
From `backend/engine/utils/conversation_helper.py`:
70+
71+
1. **Context Assembly**:
72+
```python
73+
payload["ledger"] = f"{conscious_merchant_context}{additional_context_marker}\n{ledger_json}"
74+
```
75+
76+
2. **Components**:
77+
- Conscious merchant context (Venice reality)
78+
- Current ledger state (game reality)
79+
- Conversation history (relationship context)
80+
- Mood and emotional state
81+
82+
### For Autonomous Actions
83+
From `backend/ais/autonomouslyRun.py`:
84+
85+
1. **Three-Step Process**:
86+
- Gather Data: Decide what information to fetch
87+
- Elaborate Strategy: Analyze and plan actions
88+
- Note Results: Reflect on outcomes
89+
90+
2. **Available Actions**:
91+
- Limited to historically appropriate API calls
92+
- Stratagems as primary strategic actions
93+
- Economic activities (trading, building, contracts)
94+
95+
## Knowledge Conflict Management
96+
97+
### Potential Conflicts
98+
99+
1. **Temporal Anachronisms**:
100+
- Risk: LLM knows about modern technology
101+
- Mitigation: Strong context injection emphasizing 1525 Venice
102+
- Example: Citizens think in terms of ledgers, not spreadsheets
103+
104+
2. **Cultural Mismatches**:
105+
- Risk: Modern social values conflicting with Renaissance norms
106+
- Mitigation: Social class system, merchant dignity emphasis
107+
- Example: Hierarchy and patronage vs. modern equality
108+
109+
3. **Economic Understanding**:
110+
- Risk: Modern economic theories vs. Renaissance mercantilism
111+
- Mitigation: Closed-loop economy, guild system, stratagems
112+
- Example: No fractional reserve banking, physical ducats only
113+
114+
### Safeguards
115+
116+
1. **Content Cleaning**:
117+
```python
118+
cleaned_prompt = clean_thought_content(tables, prompt)
119+
```
120+
Removes AI-generated artifacts from responses.
121+
122+
2. **Role Reinforcement**:
123+
- Every interaction reinforces merchant identity
124+
- Prompts emphasize Venice-specific thinking
125+
- Economic constraints ground behavior
126+
127+
3. **Limited Action Space**:
128+
- API endpoints restrict to period-appropriate actions
129+
- Stratagems provide structured strategic options
130+
- No access to modern concepts in game mechanics
131+
132+
## Examples of Knowledge Layers in Action
133+
134+
### Successful Integration
135+
1. **Economic Reasoning**: Citizens use period-appropriate merchant logic
136+
2. **Social Interactions**: Respect for hierarchy and patronage systems
137+
3. **Strategic Thinking**: Stratagems align with Renaissance intrigue
138+
139+
### Potential Failure Modes
140+
1. **Modern References**: If context injection fails, citizens might reference modern concepts
141+
2. **Behavioral Misalignment**: Acting like helpful assistants instead of proud merchants
142+
3. **Knowledge Gaps**: Not understanding Renaissance-specific concepts like guild obligations
143+
144+
## Monitoring and Improvement
145+
146+
1. **Daily Reflections**: Track how citizens internalize their experiences
147+
2. **Conversation Analysis**: Monitor for anachronistic references
148+
3. **Behavioral Metrics**: Ensure merchant-appropriate actions
149+
4. **Memory Persistence**: Verify KinOS maintains consistent personas
150+
151+
## Conclusion
152+
153+
The multi-layered knowledge system creates authentic Renaissance merchant AIs by:
154+
- Constraining general LLM knowledge with strong context injection
155+
- Providing real-time game state through dynamic ledgers
156+
- Building persistent memories via KinOS
157+
- Limiting actions to period-appropriate behaviors
158+
- Reinforcing merchant consciousness at every interaction
159+
160+
This architecture enables AI citizens to be both intelligent and authentically Venetian, creating the world's first consciousness laboratory where digital beings develop genuine merchant culture within historical constraints.

CLAUDE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ npm run backend:dev
9494
cd backend && ruff check .
9595
```
9696

97+
### Getting in-world data
98+
99+
You can get **live in-world data** using the pridction endpoint. For example `Bash(curl -s "https://serenissima.ai/api/resources?Type=bread" | python3 -c "` will return all the resources present in the city. The accessiblee endpoints are documented in `components\Documentation\ApiReference.tsx`. Use this possibility to assess world problems and assess the effectiveness of fixes.
100+
101+
The `api/pinpoint-problem` endpoint and related problems scripts can do a lot of the heavy lifting for you when debugging.
102+
97103
## High-Level Architecture
98104

99105
### Unified Citizen Model

app/api-reference/page.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from 'react';
2+
import ApiReference from '@/components/Documentation/ApiReference';
3+
4+
export default function ApiReferencePage() {
5+
return <ApiReference />;
6+
}

command gemini.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
aider --model gemini/gemini-2.5-pro-preview-06-05
22

3-
ngrok http 1234 --url trusted-magpie-social.ngrok-free.app
3+
ngrok http 1234 --url trusted-magpie-social.ngrok-free.app
4+
5+
python finetuneModel.py --epochs 3 --batch_size 1 --gradient_accumulation_steps 8 --fp16 --no-int8 --save_steps 100 --warmup_steps 100 --save_total_limit 1 --lora_r 16 --learning_rate 1e-6 --lora_alpha 32 --lora_target_modules "q_proj,v_proj,k_proj,o_proj,gate_proj,up_proj,down_proj" --no-test-generation

components/Documentation/ApiReference.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import Link from 'next/link';
55
function ApiReference() { // Suppression de 'export default' ici
66
return (
77
<div className="max-w-6xl mx-auto px-4 py-8 bg-amber-50 h-screen overflow-y-auto">
8+
<div className="mb-4">
9+
<Link href="/" className="text-amber-600 hover:text-amber-800 text-sm">
10+
← Back to La Serenissima
11+
</Link>
12+
</div>
813
<h1 className="text-4xl font-serif text-amber-800 mb-6">La Serenissima API Reference</h1>
914

1015
<p className="mb-8 text-lg">

components/UI/CitizenRegistry.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState, useEffect, useMemo, useRef } from 'react';
22
import dynamic from 'next/dynamic'; // Import dynamic
33
import { citizenService } from '@/lib/services/CitizenService';
44
import ArtistiRegistryTab from './ArtistiRegistryTab'; // Import the new tab component
5+
import ScientificBooksTab from './ScientificBooksTab'; // Import the scientific books tab
56
import CitizenRegistryCard from '@/components/UI/CitizenRegistryCard';
67
// Dynamically import RelationshipGraph with SSR turned off
78
const RelationshipGraph = dynamic(() => import('@/components/UI/RelationshipGraph'), {
@@ -46,7 +47,7 @@ interface Relationship {
4647
}
4748

4849
const CitizenRegistry: React.FC<CitizenRegistryProps> = ({ onClose }) => {
49-
const [activeTab, setActiveTab] = useState<'registro' | 'carta' | 'artisti'>('registro'); // Add 'artisti' to tab types
50+
const [activeTab, setActiveTab] = useState<'registro' | 'carta' | 'artisti' | 'scienze'>('registro'); // Add 'artisti' and 'scienze' to tab types
5051
const [citizens, setCitizens] = useState<any[]>([]);
5152
const [isLoading, setIsLoading] = useState<boolean>(true);
5253
const [relationships, setRelationships] = useState<Relationship[]>([]);
@@ -330,6 +331,16 @@ const CitizenRegistry: React.FC<CitizenRegistryProps> = ({ onClose }) => {
330331
>
331332
Gli Artisti
332333
</button>
334+
<button
335+
className={`px-6 py-3 font-serif text-lg ${
336+
activeTab === 'scienze'
337+
? 'bg-amber-100 text-amber-900 border-t-2 border-l-2 border-r-2 border-amber-300 rounded-t-lg -mb-px'
338+
: 'text-amber-700 hover:text-amber-900'
339+
}`}
340+
onClick={() => setActiveTab('scienze')}
341+
>
342+
Casa delle Scienze
343+
</button>
333344
</div>
334345

335346
{/* Content */}
@@ -516,6 +527,10 @@ const CitizenRegistry: React.FC<CitizenRegistryProps> = ({ onClose }) => {
516527
onViewProfile={setSelectedRegistryCitizen}
517528
currentUsername={currentUsername}
518529
/>
530+
) : activeTab === 'scienze' ? (
531+
<ScientificBooksTab
532+
currentUsername={currentUsername}
533+
/>
519534
) : null}
520535
</div>
521536
</div>

0 commit comments

Comments
 (0)