# Generated by Django 5.2 on 2025-06-26 12:20

import django.db.models.deletion
import uuid
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('api', '0044_persistentagentcommsendpoint_and_more'),
    ]

    operations = [
        migrations.CreateModel(
            name='PersistentAgentStep',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('description', models.TextField(blank=True, help_text='Narrative or raw content describing what happened in this step.')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.AddField(
            model_name='persistentagentmessage',
            name='owner_agent',
            field=models.ForeignKey(blank=True, help_text='The persistent agent this message ultimately belongs to (derived from conversation or endpoint)', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='agent_messages', to='api.persistentagent'),
        ),
        migrations.AddIndex(
            model_name='persistentagentmessage',
            index=models.Index(fields=['owner_agent', '-timestamp'], name='pa_msg_agent_ts_idx'),
        ),
        migrations.AddField(
            model_name='persistentagentstep',
            name='agent',
            field=models.ForeignKey(help_text='The persistent agent that executed this step', on_delete=django.db.models.deletion.CASCADE, related_name='steps', to='api.persistentagent'),
        ),
        migrations.CreateModel(
            name='PersistentAgentToolCall',
            fields=[
                ('step', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, related_name='tool_call', serialize=False, to='api.persistentagentstep')),
                ('tool_name', models.CharField(max_length=256)),
                ('tool_params', models.JSONField(blank=True, null=True)),
                ('result', models.TextField(blank=True, help_text='Raw result or output from the tool call (may be large)')),
            ],
            options={
                'ordering': ['-step__created_at'],
                'indexes': [models.Index(fields=['tool_name'], name='pa_tool_name_idx')],
            },
        ),
        migrations.AddIndex(
            model_name='persistentagentstep',
            index=models.Index(fields=['agent', '-created_at'], name='pa_step_recent_idx'),
        ),
    ]
