django-agent-runtime 0.3.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- django_agent_runtime/__init__.py +25 -0
- django_agent_runtime/admin.py +155 -0
- django_agent_runtime/api/__init__.py +26 -0
- django_agent_runtime/api/permissions.py +109 -0
- django_agent_runtime/api/serializers.py +114 -0
- django_agent_runtime/api/views.py +472 -0
- django_agent_runtime/apps.py +26 -0
- django_agent_runtime/conf.py +241 -0
- django_agent_runtime/examples/__init__.py +10 -0
- django_agent_runtime/examples/langgraph_adapter.py +164 -0
- django_agent_runtime/examples/langgraph_tools.py +179 -0
- django_agent_runtime/examples/simple_chat.py +69 -0
- django_agent_runtime/examples/tool_agent.py +157 -0
- django_agent_runtime/management/__init__.py +2 -0
- django_agent_runtime/management/commands/__init__.py +2 -0
- django_agent_runtime/management/commands/runagent.py +419 -0
- django_agent_runtime/migrations/0001_initial.py +117 -0
- django_agent_runtime/migrations/0002_persistence_models.py +129 -0
- django_agent_runtime/migrations/0003_persistenceconversation_active_branch_id_and_more.py +212 -0
- django_agent_runtime/migrations/0004_add_anonymous_session_id.py +18 -0
- django_agent_runtime/migrations/__init__.py +2 -0
- django_agent_runtime/models/__init__.py +54 -0
- django_agent_runtime/models/base.py +450 -0
- django_agent_runtime/models/concrete.py +146 -0
- django_agent_runtime/persistence/__init__.py +60 -0
- django_agent_runtime/persistence/helpers.py +148 -0
- django_agent_runtime/persistence/models.py +506 -0
- django_agent_runtime/persistence/stores.py +1191 -0
- django_agent_runtime/runtime/__init__.py +23 -0
- django_agent_runtime/runtime/events/__init__.py +65 -0
- django_agent_runtime/runtime/events/base.py +135 -0
- django_agent_runtime/runtime/events/db.py +129 -0
- django_agent_runtime/runtime/events/redis.py +228 -0
- django_agent_runtime/runtime/events/sync.py +140 -0
- django_agent_runtime/runtime/interfaces.py +475 -0
- django_agent_runtime/runtime/llm/__init__.py +91 -0
- django_agent_runtime/runtime/llm/anthropic.py +249 -0
- django_agent_runtime/runtime/llm/litellm_adapter.py +173 -0
- django_agent_runtime/runtime/llm/openai.py +230 -0
- django_agent_runtime/runtime/queue/__init__.py +75 -0
- django_agent_runtime/runtime/queue/base.py +158 -0
- django_agent_runtime/runtime/queue/postgres.py +248 -0
- django_agent_runtime/runtime/queue/redis_streams.py +336 -0
- django_agent_runtime/runtime/queue/sync.py +277 -0
- django_agent_runtime/runtime/registry.py +186 -0
- django_agent_runtime/runtime/runner.py +540 -0
- django_agent_runtime/runtime/tracing/__init__.py +48 -0
- django_agent_runtime/runtime/tracing/langfuse.py +117 -0
- django_agent_runtime/runtime/tracing/noop.py +36 -0
- django_agent_runtime/urls.py +39 -0
- django_agent_runtime-0.3.6.dist-info/METADATA +723 -0
- django_agent_runtime-0.3.6.dist-info/RECORD +55 -0
- django_agent_runtime-0.3.6.dist-info/WHEEL +5 -0
- django_agent_runtime-0.3.6.dist-info/licenses/LICENSE +22 -0
- django_agent_runtime-0.3.6.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Generated by Django 5.2.5 on 2025-12-31 13:31
|
|
2
|
+
|
|
3
|
+
import django.db.models.deletion
|
|
4
|
+
import uuid
|
|
5
|
+
from django.conf import settings
|
|
6
|
+
from django.db import migrations, models
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Migration(migrations.Migration):
|
|
10
|
+
|
|
11
|
+
initial = True
|
|
12
|
+
|
|
13
|
+
dependencies = [
|
|
14
|
+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
operations = [
|
|
18
|
+
migrations.CreateModel(
|
|
19
|
+
name='AgentConversation',
|
|
20
|
+
fields=[
|
|
21
|
+
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
22
|
+
('agent_key', models.CharField(db_index=True, help_text='Identifier for the agent runtime to use', max_length=100)),
|
|
23
|
+
('title', models.CharField(blank=True, max_length=255)),
|
|
24
|
+
('metadata', models.JSONField(blank=True, default=dict)),
|
|
25
|
+
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
|
|
26
|
+
('updated_at', models.DateTimeField(auto_now=True)),
|
|
27
|
+
('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='agent_conversations', to=settings.AUTH_USER_MODEL)),
|
|
28
|
+
],
|
|
29
|
+
options={
|
|
30
|
+
'verbose_name': 'Agent Conversation',
|
|
31
|
+
'verbose_name_plural': 'Agent Conversations',
|
|
32
|
+
'db_table': 'agent_runtime_conversation',
|
|
33
|
+
'ordering': ['-created_at'],
|
|
34
|
+
'abstract': False,
|
|
35
|
+
},
|
|
36
|
+
),
|
|
37
|
+
migrations.CreateModel(
|
|
38
|
+
name='AgentRun',
|
|
39
|
+
fields=[
|
|
40
|
+
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
41
|
+
('agent_key', models.CharField(db_index=True, help_text='Identifier for the agent runtime to use', max_length=100)),
|
|
42
|
+
('status', models.CharField(choices=[('queued', 'Queued'), ('running', 'Running'), ('succeeded', 'Succeeded'), ('failed', 'Failed'), ('cancelled', 'Cancelled'), ('timed_out', 'Timed Out')], db_index=True, default='queued', max_length=20)),
|
|
43
|
+
('input', models.JSONField(default=dict, help_text='{"messages": [...], "params": {...}}')),
|
|
44
|
+
('output', models.JSONField(blank=True, default=dict, help_text='Final output from the agent')),
|
|
45
|
+
('error', models.JSONField(blank=True, default=dict, help_text='{"type": "", "message": "", "stack": "", "retriable": true}')),
|
|
46
|
+
('attempt', models.PositiveIntegerField(default=1)),
|
|
47
|
+
('max_attempts', models.PositiveIntegerField(default=3)),
|
|
48
|
+
('lease_owner', models.CharField(blank=True, db_index=True, help_text='Worker ID that owns this run', max_length=100)),
|
|
49
|
+
('lease_expires_at', models.DateTimeField(blank=True, db_index=True, help_text='When the lease expires', null=True)),
|
|
50
|
+
('idempotency_key', models.CharField(blank=True, help_text='Client-provided key for idempotent requests', max_length=255, null=True, unique=True)),
|
|
51
|
+
('cancel_requested_at', models.DateTimeField(blank=True, help_text='When cancellation was requested', null=True)),
|
|
52
|
+
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
|
|
53
|
+
('started_at', models.DateTimeField(blank=True, null=True)),
|
|
54
|
+
('finished_at', models.DateTimeField(blank=True, null=True)),
|
|
55
|
+
('metadata', models.JSONField(blank=True, default=dict)),
|
|
56
|
+
('conversation', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='runs', to='django_agent_runtime.agentconversation')),
|
|
57
|
+
],
|
|
58
|
+
options={
|
|
59
|
+
'verbose_name': 'Agent Run',
|
|
60
|
+
'verbose_name_plural': 'Agent Runs',
|
|
61
|
+
'db_table': 'agent_runtime_run',
|
|
62
|
+
'ordering': ['-created_at'],
|
|
63
|
+
'abstract': False,
|
|
64
|
+
},
|
|
65
|
+
),
|
|
66
|
+
migrations.CreateModel(
|
|
67
|
+
name='AgentEvent',
|
|
68
|
+
fields=[
|
|
69
|
+
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
70
|
+
('seq', models.PositiveIntegerField(db_index=True, help_text='Strictly increasing sequence number per run')),
|
|
71
|
+
('event_type', models.CharField(db_index=True, help_text='Event type (e.g., run.started, assistant.message)', max_length=50)),
|
|
72
|
+
('payload', models.JSONField(default=dict)),
|
|
73
|
+
('timestamp', models.DateTimeField(auto_now_add=True, db_index=True)),
|
|
74
|
+
('run', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='events', to='django_agent_runtime.agentrun')),
|
|
75
|
+
],
|
|
76
|
+
options={
|
|
77
|
+
'verbose_name': 'Agent Event',
|
|
78
|
+
'verbose_name_plural': 'Agent Events',
|
|
79
|
+
'db_table': 'agent_runtime_event',
|
|
80
|
+
'ordering': ['seq'],
|
|
81
|
+
'abstract': False,
|
|
82
|
+
},
|
|
83
|
+
),
|
|
84
|
+
migrations.CreateModel(
|
|
85
|
+
name='AgentCheckpoint',
|
|
86
|
+
fields=[
|
|
87
|
+
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
88
|
+
('state', models.JSONField(help_text='Serialized agent state for recovery')),
|
|
89
|
+
('seq', models.PositiveIntegerField(help_text='Checkpoint sequence number')),
|
|
90
|
+
('created_at', models.DateTimeField(auto_now_add=True)),
|
|
91
|
+
('run', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='checkpoints', to='django_agent_runtime.agentrun')),
|
|
92
|
+
],
|
|
93
|
+
options={
|
|
94
|
+
'verbose_name': 'Agent Checkpoint',
|
|
95
|
+
'verbose_name_plural': 'Agent Checkpoints',
|
|
96
|
+
'db_table': 'agent_runtime_checkpoint',
|
|
97
|
+
'ordering': ['-seq'],
|
|
98
|
+
'abstract': False,
|
|
99
|
+
},
|
|
100
|
+
),
|
|
101
|
+
migrations.AddIndex(
|
|
102
|
+
model_name='agentrun',
|
|
103
|
+
index=models.Index(fields=['status', 'lease_expires_at'], name='agent_runti_status_8d673e_idx'),
|
|
104
|
+
),
|
|
105
|
+
migrations.AddIndex(
|
|
106
|
+
model_name='agentrun',
|
|
107
|
+
index=models.Index(fields=['agent_key', 'status'], name='agent_runti_agent_k_ce0439_idx'),
|
|
108
|
+
),
|
|
109
|
+
migrations.AlterUniqueTogether(
|
|
110
|
+
name='agentevent',
|
|
111
|
+
unique_together={('run', 'seq')},
|
|
112
|
+
),
|
|
113
|
+
migrations.AlterUniqueTogether(
|
|
114
|
+
name='agentcheckpoint',
|
|
115
|
+
unique_together={('run', 'seq')},
|
|
116
|
+
),
|
|
117
|
+
]
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Generated by Django 5.2.9 on 2026-01-12 19:28
|
|
2
|
+
|
|
3
|
+
import django.db.models.deletion
|
|
4
|
+
import uuid
|
|
5
|
+
from django.conf import settings
|
|
6
|
+
from django.db import migrations, models
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Migration(migrations.Migration):
|
|
10
|
+
|
|
11
|
+
dependencies = [
|
|
12
|
+
('django_agent_runtime', '0001_initial'),
|
|
13
|
+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
operations = [
|
|
17
|
+
migrations.CreateModel(
|
|
18
|
+
name='PersistenceConversation',
|
|
19
|
+
fields=[
|
|
20
|
+
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
21
|
+
('title', models.CharField(blank=True, max_length=255)),
|
|
22
|
+
('agent_key', models.CharField(blank=True, db_index=True, max_length=100)),
|
|
23
|
+
('summary', models.TextField(blank=True)),
|
|
24
|
+
('metadata', models.JSONField(blank=True, default=dict)),
|
|
25
|
+
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
|
|
26
|
+
('updated_at', models.DateTimeField(auto_now=True)),
|
|
27
|
+
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='persistence_conversations', to=settings.AUTH_USER_MODEL)),
|
|
28
|
+
],
|
|
29
|
+
options={
|
|
30
|
+
'verbose_name': 'Persistence Conversation',
|
|
31
|
+
'verbose_name_plural': 'Persistence Conversations',
|
|
32
|
+
'db_table': 'agent_runtime_persistence_conversation',
|
|
33
|
+
'ordering': ['-updated_at'],
|
|
34
|
+
},
|
|
35
|
+
),
|
|
36
|
+
migrations.CreateModel(
|
|
37
|
+
name='PersistenceMessage',
|
|
38
|
+
fields=[
|
|
39
|
+
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
40
|
+
('role', models.CharField(max_length=20)),
|
|
41
|
+
('content', models.JSONField()),
|
|
42
|
+
('tool_calls', models.JSONField(blank=True, default=list)),
|
|
43
|
+
('tool_call_id', models.CharField(blank=True, max_length=255)),
|
|
44
|
+
('model', models.CharField(blank=True, max_length=100)),
|
|
45
|
+
('usage', models.JSONField(blank=True, default=dict)),
|
|
46
|
+
('metadata', models.JSONField(blank=True, default=dict)),
|
|
47
|
+
('timestamp', models.DateTimeField(auto_now_add=True, db_index=True)),
|
|
48
|
+
('conversation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='messages', to='django_agent_runtime.persistenceconversation')),
|
|
49
|
+
],
|
|
50
|
+
options={
|
|
51
|
+
'verbose_name': 'Persistence Message',
|
|
52
|
+
'verbose_name_plural': 'Persistence Messages',
|
|
53
|
+
'db_table': 'agent_runtime_persistence_message',
|
|
54
|
+
'ordering': ['timestamp'],
|
|
55
|
+
},
|
|
56
|
+
),
|
|
57
|
+
migrations.CreateModel(
|
|
58
|
+
name='PersistenceTaskList',
|
|
59
|
+
fields=[
|
|
60
|
+
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
61
|
+
('name', models.CharField(max_length=255)),
|
|
62
|
+
('conversation_id', models.UUIDField(blank=True, db_index=True, null=True)),
|
|
63
|
+
('run_id', models.UUIDField(blank=True, db_index=True, null=True)),
|
|
64
|
+
('created_at', models.DateTimeField(auto_now_add=True)),
|
|
65
|
+
('updated_at', models.DateTimeField(auto_now=True)),
|
|
66
|
+
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='persistence_task_lists', to=settings.AUTH_USER_MODEL)),
|
|
67
|
+
],
|
|
68
|
+
options={
|
|
69
|
+
'verbose_name': 'Persistence Task List',
|
|
70
|
+
'verbose_name_plural': 'Persistence Task Lists',
|
|
71
|
+
'db_table': 'agent_runtime_persistence_task_list',
|
|
72
|
+
'ordering': ['-updated_at'],
|
|
73
|
+
},
|
|
74
|
+
),
|
|
75
|
+
migrations.CreateModel(
|
|
76
|
+
name='PersistenceTask',
|
|
77
|
+
fields=[
|
|
78
|
+
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
79
|
+
('name', models.CharField(max_length=255)),
|
|
80
|
+
('description', models.TextField(blank=True)),
|
|
81
|
+
('state', models.CharField(choices=[('not_started', 'Not Started'), ('in_progress', 'In Progress'), ('complete', 'Complete'), ('cancelled', 'Cancelled')], default='not_started', max_length=20)),
|
|
82
|
+
('parent_id', models.UUIDField(blank=True, null=True)),
|
|
83
|
+
('metadata', models.JSONField(blank=True, default=dict)),
|
|
84
|
+
('created_at', models.DateTimeField(auto_now_add=True)),
|
|
85
|
+
('updated_at', models.DateTimeField(auto_now=True)),
|
|
86
|
+
('task_list', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tasks', to='django_agent_runtime.persistencetasklist')),
|
|
87
|
+
],
|
|
88
|
+
options={
|
|
89
|
+
'verbose_name': 'Persistence Task',
|
|
90
|
+
'verbose_name_plural': 'Persistence Tasks',
|
|
91
|
+
'db_table': 'agent_runtime_persistence_task',
|
|
92
|
+
'ordering': ['created_at'],
|
|
93
|
+
},
|
|
94
|
+
),
|
|
95
|
+
migrations.CreateModel(
|
|
96
|
+
name='Memory',
|
|
97
|
+
fields=[
|
|
98
|
+
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
99
|
+
('key', models.CharField(db_index=True, max_length=255)),
|
|
100
|
+
('value', models.JSONField()),
|
|
101
|
+
('created_at', models.DateTimeField(auto_now_add=True)),
|
|
102
|
+
('updated_at', models.DateTimeField(auto_now=True)),
|
|
103
|
+
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='agent_memories', to=settings.AUTH_USER_MODEL)),
|
|
104
|
+
],
|
|
105
|
+
options={
|
|
106
|
+
'verbose_name': 'Agent Memory',
|
|
107
|
+
'verbose_name_plural': 'Agent Memories',
|
|
108
|
+
'db_table': 'agent_runtime_memory',
|
|
109
|
+
'unique_together': {('user', 'key')},
|
|
110
|
+
},
|
|
111
|
+
),
|
|
112
|
+
migrations.CreateModel(
|
|
113
|
+
name='Preferences',
|
|
114
|
+
fields=[
|
|
115
|
+
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
116
|
+
('key', models.CharField(db_index=True, max_length=255)),
|
|
117
|
+
('value', models.JSONField()),
|
|
118
|
+
('created_at', models.DateTimeField(auto_now_add=True)),
|
|
119
|
+
('updated_at', models.DateTimeField(auto_now=True)),
|
|
120
|
+
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='agent_preferences', to=settings.AUTH_USER_MODEL)),
|
|
121
|
+
],
|
|
122
|
+
options={
|
|
123
|
+
'verbose_name': 'Agent Preference',
|
|
124
|
+
'verbose_name_plural': 'Agent Preferences',
|
|
125
|
+
'db_table': 'agent_runtime_preferences',
|
|
126
|
+
'unique_together': {('user', 'key')},
|
|
127
|
+
},
|
|
128
|
+
),
|
|
129
|
+
]
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# Generated by Django 5.2.9 on 2026-01-12 20:12
|
|
2
|
+
|
|
3
|
+
import django.db.models.deletion
|
|
4
|
+
import uuid
|
|
5
|
+
from django.conf import settings
|
|
6
|
+
from django.db import migrations, models
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Migration(migrations.Migration):
|
|
10
|
+
|
|
11
|
+
dependencies = [
|
|
12
|
+
('django_agent_runtime', '0002_persistence_models'),
|
|
13
|
+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
operations = [
|
|
17
|
+
migrations.AddField(
|
|
18
|
+
model_name='persistenceconversation',
|
|
19
|
+
name='active_branch_id',
|
|
20
|
+
field=models.UUIDField(blank=True, null=True),
|
|
21
|
+
),
|
|
22
|
+
migrations.AddField(
|
|
23
|
+
model_name='persistenceconversation',
|
|
24
|
+
name='parent_conversation_id',
|
|
25
|
+
field=models.UUIDField(blank=True, db_index=True, null=True),
|
|
26
|
+
),
|
|
27
|
+
migrations.AddField(
|
|
28
|
+
model_name='persistencemessage',
|
|
29
|
+
name='branch_id',
|
|
30
|
+
field=models.UUIDField(blank=True, db_index=True, null=True),
|
|
31
|
+
),
|
|
32
|
+
migrations.AddField(
|
|
33
|
+
model_name='persistencemessage',
|
|
34
|
+
name='parent_message_id',
|
|
35
|
+
field=models.UUIDField(blank=True, db_index=True, null=True),
|
|
36
|
+
),
|
|
37
|
+
migrations.AddField(
|
|
38
|
+
model_name='persistencetask',
|
|
39
|
+
name='attempts',
|
|
40
|
+
field=models.IntegerField(default=0),
|
|
41
|
+
),
|
|
42
|
+
migrations.AddField(
|
|
43
|
+
model_name='persistencetask',
|
|
44
|
+
name='checkpoint_at',
|
|
45
|
+
field=models.DateTimeField(blank=True, null=True),
|
|
46
|
+
),
|
|
47
|
+
migrations.AddField(
|
|
48
|
+
model_name='persistencetask',
|
|
49
|
+
name='checkpoint_data',
|
|
50
|
+
field=models.JSONField(blank=True, default=dict),
|
|
51
|
+
),
|
|
52
|
+
migrations.AddField(
|
|
53
|
+
model_name='persistencetask',
|
|
54
|
+
name='completed_at',
|
|
55
|
+
field=models.DateTimeField(blank=True, null=True),
|
|
56
|
+
),
|
|
57
|
+
migrations.AddField(
|
|
58
|
+
model_name='persistencetask',
|
|
59
|
+
name='dependencies',
|
|
60
|
+
field=models.JSONField(blank=True, default=list),
|
|
61
|
+
),
|
|
62
|
+
migrations.AddField(
|
|
63
|
+
model_name='persistencetask',
|
|
64
|
+
name='due_at',
|
|
65
|
+
field=models.DateTimeField(blank=True, null=True),
|
|
66
|
+
),
|
|
67
|
+
migrations.AddField(
|
|
68
|
+
model_name='persistencetask',
|
|
69
|
+
name='last_error',
|
|
70
|
+
field=models.TextField(blank=True),
|
|
71
|
+
),
|
|
72
|
+
migrations.AddField(
|
|
73
|
+
model_name='persistencetask',
|
|
74
|
+
name='priority',
|
|
75
|
+
field=models.IntegerField(default=0),
|
|
76
|
+
),
|
|
77
|
+
migrations.CreateModel(
|
|
78
|
+
name='AuditEntry',
|
|
79
|
+
fields=[
|
|
80
|
+
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
81
|
+
('event_type', models.CharField(choices=[('conversation_start', 'Conversation Start'), ('conversation_end', 'Conversation End'), ('message_sent', 'Message Sent'), ('message_received', 'Message Received'), ('tool_call', 'Tool Call'), ('tool_result', 'Tool Result'), ('tool_error', 'Tool Error'), ('agent_start', 'Agent Start'), ('agent_end', 'Agent End'), ('agent_error', 'Agent Error'), ('checkpoint_saved', 'Checkpoint Saved'), ('checkpoint_restored', 'Checkpoint Restored'), ('custom', 'Custom')], db_index=True, max_length=30)),
|
|
82
|
+
('timestamp', models.DateTimeField(auto_now_add=True, db_index=True)),
|
|
83
|
+
('conversation_id', models.UUIDField(blank=True, db_index=True, null=True)),
|
|
84
|
+
('run_id', models.UUIDField(blank=True, db_index=True, null=True)),
|
|
85
|
+
('agent_key', models.CharField(blank=True, db_index=True, max_length=100)),
|
|
86
|
+
('action', models.CharField(blank=True, max_length=255)),
|
|
87
|
+
('details', models.JSONField(blank=True, default=dict)),
|
|
88
|
+
('actor_type', models.CharField(default='agent', max_length=20)),
|
|
89
|
+
('actor_id', models.CharField(blank=True, max_length=255)),
|
|
90
|
+
('request_id', models.CharField(blank=True, max_length=255)),
|
|
91
|
+
('parent_event_id', models.UUIDField(blank=True, null=True)),
|
|
92
|
+
('metadata', models.JSONField(blank=True, default=dict)),
|
|
93
|
+
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='agent_audit_entries', to=settings.AUTH_USER_MODEL)),
|
|
94
|
+
],
|
|
95
|
+
options={
|
|
96
|
+
'verbose_name': 'Audit Entry',
|
|
97
|
+
'verbose_name_plural': 'Audit Entries',
|
|
98
|
+
'db_table': 'agent_runtime_audit_entry',
|
|
99
|
+
'ordering': ['-timestamp'],
|
|
100
|
+
},
|
|
101
|
+
),
|
|
102
|
+
migrations.CreateModel(
|
|
103
|
+
name='Embedding',
|
|
104
|
+
fields=[
|
|
105
|
+
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
106
|
+
('vector', models.JSONField()),
|
|
107
|
+
('content', models.TextField()),
|
|
108
|
+
('content_type', models.CharField(db_index=True, default='text', max_length=50)),
|
|
109
|
+
('source_id', models.UUIDField(blank=True, db_index=True, null=True)),
|
|
110
|
+
('model', models.CharField(blank=True, max_length=100)),
|
|
111
|
+
('dimensions', models.IntegerField(default=0)),
|
|
112
|
+
('metadata', models.JSONField(blank=True, default=dict)),
|
|
113
|
+
('created_at', models.DateTimeField(auto_now_add=True)),
|
|
114
|
+
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='agent_embeddings', to=settings.AUTH_USER_MODEL)),
|
|
115
|
+
],
|
|
116
|
+
options={
|
|
117
|
+
'verbose_name': 'Embedding',
|
|
118
|
+
'verbose_name_plural': 'Embeddings',
|
|
119
|
+
'db_table': 'agent_runtime_embedding',
|
|
120
|
+
},
|
|
121
|
+
),
|
|
122
|
+
migrations.CreateModel(
|
|
123
|
+
name='ErrorRecord',
|
|
124
|
+
fields=[
|
|
125
|
+
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
126
|
+
('timestamp', models.DateTimeField(auto_now_add=True, db_index=True)),
|
|
127
|
+
('severity', models.CharField(choices=[('debug', 'Debug'), ('info', 'Info'), ('warning', 'Warning'), ('error', 'Error'), ('critical', 'Critical')], db_index=True, default='error', max_length=10)),
|
|
128
|
+
('error_type', models.CharField(blank=True, max_length=255)),
|
|
129
|
+
('message', models.TextField(blank=True)),
|
|
130
|
+
('stack_trace', models.TextField(blank=True)),
|
|
131
|
+
('conversation_id', models.UUIDField(blank=True, db_index=True, null=True)),
|
|
132
|
+
('run_id', models.UUIDField(blank=True, db_index=True, null=True)),
|
|
133
|
+
('agent_key', models.CharField(blank=True, db_index=True, max_length=100)),
|
|
134
|
+
('context', models.JSONField(blank=True, default=dict)),
|
|
135
|
+
('resolved', models.BooleanField(db_index=True, default=False)),
|
|
136
|
+
('resolved_at', models.DateTimeField(blank=True, null=True)),
|
|
137
|
+
('resolution_notes', models.TextField(blank=True)),
|
|
138
|
+
('metadata', models.JSONField(blank=True, default=dict)),
|
|
139
|
+
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='agent_error_records', to=settings.AUTH_USER_MODEL)),
|
|
140
|
+
],
|
|
141
|
+
options={
|
|
142
|
+
'verbose_name': 'Error Record',
|
|
143
|
+
'verbose_name_plural': 'Error Records',
|
|
144
|
+
'db_table': 'agent_runtime_error_record',
|
|
145
|
+
'ordering': ['-timestamp'],
|
|
146
|
+
},
|
|
147
|
+
),
|
|
148
|
+
migrations.CreateModel(
|
|
149
|
+
name='PerformanceMetric',
|
|
150
|
+
fields=[
|
|
151
|
+
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
152
|
+
('name', models.CharField(db_index=True, max_length=100)),
|
|
153
|
+
('value', models.FloatField()),
|
|
154
|
+
('unit', models.CharField(blank=True, max_length=20)),
|
|
155
|
+
('timestamp', models.DateTimeField(auto_now_add=True, db_index=True)),
|
|
156
|
+
('conversation_id', models.UUIDField(blank=True, db_index=True, null=True)),
|
|
157
|
+
('run_id', models.UUIDField(blank=True, db_index=True, null=True)),
|
|
158
|
+
('agent_key', models.CharField(blank=True, db_index=True, max_length=100)),
|
|
159
|
+
('tags', models.JSONField(blank=True, default=dict)),
|
|
160
|
+
('metadata', models.JSONField(blank=True, default=dict)),
|
|
161
|
+
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='agent_performance_metrics', to=settings.AUTH_USER_MODEL)),
|
|
162
|
+
],
|
|
163
|
+
options={
|
|
164
|
+
'verbose_name': 'Performance Metric',
|
|
165
|
+
'verbose_name_plural': 'Performance Metrics',
|
|
166
|
+
'db_table': 'agent_runtime_performance_metric',
|
|
167
|
+
'ordering': ['-timestamp'],
|
|
168
|
+
},
|
|
169
|
+
),
|
|
170
|
+
migrations.CreateModel(
|
|
171
|
+
name='Summary',
|
|
172
|
+
fields=[
|
|
173
|
+
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
174
|
+
('content', models.TextField()),
|
|
175
|
+
('conversation_id', models.UUIDField(blank=True, db_index=True, null=True)),
|
|
176
|
+
('conversation_ids', models.JSONField(blank=True, default=list)),
|
|
177
|
+
('start_time', models.DateTimeField(blank=True, null=True)),
|
|
178
|
+
('end_time', models.DateTimeField(blank=True, null=True)),
|
|
179
|
+
('metadata', models.JSONField(blank=True, default=dict)),
|
|
180
|
+
('created_at', models.DateTimeField(auto_now_add=True)),
|
|
181
|
+
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='agent_summaries', to=settings.AUTH_USER_MODEL)),
|
|
182
|
+
],
|
|
183
|
+
options={
|
|
184
|
+
'verbose_name': 'Summary',
|
|
185
|
+
'verbose_name_plural': 'Summaries',
|
|
186
|
+
'db_table': 'agent_runtime_summary',
|
|
187
|
+
'ordering': ['-created_at'],
|
|
188
|
+
},
|
|
189
|
+
),
|
|
190
|
+
migrations.CreateModel(
|
|
191
|
+
name='Fact',
|
|
192
|
+
fields=[
|
|
193
|
+
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
194
|
+
('key', models.CharField(db_index=True, max_length=255)),
|
|
195
|
+
('value', models.JSONField()),
|
|
196
|
+
('fact_type', models.CharField(choices=[('user', 'User'), ('project', 'Project'), ('preference', 'Preference'), ('context', 'Context'), ('custom', 'Custom')], db_index=True, default='custom', max_length=20)),
|
|
197
|
+
('confidence', models.FloatField(default=1.0)),
|
|
198
|
+
('source', models.CharField(blank=True, max_length=255)),
|
|
199
|
+
('expires_at', models.DateTimeField(blank=True, db_index=True, null=True)),
|
|
200
|
+
('metadata', models.JSONField(blank=True, default=dict)),
|
|
201
|
+
('created_at', models.DateTimeField(auto_now_add=True)),
|
|
202
|
+
('updated_at', models.DateTimeField(auto_now=True)),
|
|
203
|
+
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='agent_facts', to=settings.AUTH_USER_MODEL)),
|
|
204
|
+
],
|
|
205
|
+
options={
|
|
206
|
+
'verbose_name': 'Fact',
|
|
207
|
+
'verbose_name_plural': 'Facts',
|
|
208
|
+
'db_table': 'agent_runtime_fact',
|
|
209
|
+
'unique_together': {('user', 'key')},
|
|
210
|
+
},
|
|
211
|
+
),
|
|
212
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Generated by Django 5.2.9 on 2026-01-13 00:21
|
|
2
|
+
|
|
3
|
+
from django.db import migrations, models
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Migration(migrations.Migration):
|
|
7
|
+
|
|
8
|
+
dependencies = [
|
|
9
|
+
('django_agent_runtime', '0003_persistenceconversation_active_branch_id_and_more'),
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
operations = [
|
|
13
|
+
migrations.AddField(
|
|
14
|
+
model_name='agentconversation',
|
|
15
|
+
name='anonymous_session_id',
|
|
16
|
+
field=models.UUIDField(blank=True, db_index=True, help_text='UUID of the anonymous session (if using anonymous sessions)', null=True),
|
|
17
|
+
),
|
|
18
|
+
]
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Django models for the Agent Runtime.
|
|
3
|
+
|
|
4
|
+
Provides:
|
|
5
|
+
- AgentConversation: Groups related runs
|
|
6
|
+
- AgentRun: Individual agent execution
|
|
7
|
+
- AgentEvent: Append-only event log
|
|
8
|
+
- AgentCheckpoint: State snapshots for recovery
|
|
9
|
+
- Persistence models: Memory, Conversation, Message, Task, Preferences
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from django_agent_runtime.models.base import (
|
|
13
|
+
AbstractAgentConversation,
|
|
14
|
+
AbstractAgentRun,
|
|
15
|
+
AbstractAgentEvent,
|
|
16
|
+
AbstractAgentCheckpoint,
|
|
17
|
+
)
|
|
18
|
+
from django_agent_runtime.models.concrete import (
|
|
19
|
+
AgentConversation,
|
|
20
|
+
AgentRun,
|
|
21
|
+
AgentEvent,
|
|
22
|
+
AgentCheckpoint,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
# Import persistence models so Django can discover them
|
|
26
|
+
from django_agent_runtime.persistence.models import (
|
|
27
|
+
Memory,
|
|
28
|
+
PersistenceConversation,
|
|
29
|
+
PersistenceMessage,
|
|
30
|
+
PersistenceTaskList,
|
|
31
|
+
PersistenceTask,
|
|
32
|
+
Preferences,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
__all__ = [
|
|
36
|
+
# Abstract models (for custom implementations)
|
|
37
|
+
"AbstractAgentConversation",
|
|
38
|
+
"AbstractAgentRun",
|
|
39
|
+
"AbstractAgentEvent",
|
|
40
|
+
"AbstractAgentCheckpoint",
|
|
41
|
+
# Concrete models (default implementation)
|
|
42
|
+
"AgentConversation",
|
|
43
|
+
"AgentRun",
|
|
44
|
+
"AgentEvent",
|
|
45
|
+
"AgentCheckpoint",
|
|
46
|
+
# Persistence models
|
|
47
|
+
"Memory",
|
|
48
|
+
"PersistenceConversation",
|
|
49
|
+
"PersistenceMessage",
|
|
50
|
+
"PersistenceTaskList",
|
|
51
|
+
"PersistenceTask",
|
|
52
|
+
"Preferences",
|
|
53
|
+
]
|
|
54
|
+
|