StoreAgentTraceRequest.php 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Http\Requests\V3;
  3. use App\Models\AgentRun;
  4. use App\Models\AgentThread;
  5. use Illuminate\Foundation\Http\FormRequest;
  6. use Illuminate\Validation\Rule;
  7. /**
  8. * `POST /v3/agent-traces` 的入参:一次提问(AG-UI run)的研究过程,连同全部步骤。
  9. *
  10. * 由 agent 服务在一次运行结束后发来。长文本的上限按「一次运行里最多会有多少」
  11. * 留余量:证据全文给作答 LLM,深度思考时几万字也正常;单步结果 agent 端已截断到 8k。
  12. */
  13. class StoreAgentTraceRequest extends FormRequest
  14. {
  15. public function authorize(): bool
  16. {
  17. return true;
  18. }
  19. /**
  20. * @return array<string, array<int, mixed>>
  21. */
  22. public function rules(): array
  23. {
  24. return [
  25. 'run_id' => ['required', 'uuid'],
  26. 'thread_id' => ['required', 'uuid'],
  27. 'device_id' => ['nullable', 'uuid'],
  28. 'client_ip' => ['nullable', 'ip'],
  29. 'client' => ['nullable', 'string', Rule::in(AgentThread::CLIENTS)],
  30. 'app_version' => ['nullable', 'string', 'max:32'],
  31. 'locale' => ['nullable', 'string', 'max:16'],
  32. 'question' => ['required', 'string', 'max:20000'],
  33. 'passage' => ['nullable', 'array'],
  34. 'deep' => ['boolean'],
  35. 'improve' => ['boolean'],
  36. 'route' => ['nullable', 'string', 'max:32'],
  37. 'route_raw' => ['nullable', 'string', 'max:32'],
  38. 'confidence' => ['nullable', 'numeric'],
  39. 'plan' => ['nullable', 'array'],
  40. 'evidence' => ['nullable', 'string', 'max:400000'],
  41. 'answer' => ['nullable', 'string', 'max:200000'],
  42. 'citations' => ['nullable', 'array', 'max:200'],
  43. 'model' => ['nullable', 'string', 'max:64'],
  44. 'prompt_version' => ['nullable', 'string', 'max:64'],
  45. 'llm_calls' => ['integer', 'min:0', 'max:65535'],
  46. 'tool_calls' => ['integer', 'min:0', 'max:65535'],
  47. 'retries' => ['integer', 'min:0', 'max:65535'],
  48. 'tokens_in' => ['nullable', 'integer', 'min:0'],
  49. 'tokens_out' => ['nullable', 'integer', 'min:0'],
  50. 'latency_ms' => ['nullable', 'integer', 'min:0'],
  51. 'status' => ['required', 'string', Rule::in(AgentRun::STATUSES)],
  52. 'error' => ['nullable', 'string', 'max:20000'],
  53. 'user_message_id' => ['nullable', 'string', 'max:64'],
  54. 'assistant_message_id' => ['nullable', 'string', 'max:64'],
  55. 'replaces_run_id' => ['nullable', 'uuid'],
  56. // 「重新生成」时被替换那条回答的 AG-UI 消息 id;服务端在同一会话里换算成 replaces_run_id
  57. 'replaces_message_id' => ['nullable', 'string', 'max:64'],
  58. 'started_at' => ['nullable', 'date'],
  59. 'steps' => ['array', 'max:500'],
  60. 'steps.*.seq' => ['required', 'integer', 'min:0', 'max:65535', 'distinct'],
  61. // 不限定取值:backend 新加的步骤类型照样入库(不认识的记警告),不能因此整条被拒
  62. 'steps.*.kind' => ['required', 'string', 'max:16'],
  63. 'steps.*.name' => ['nullable', 'string', 'max:128'],
  64. 'steps.*.args' => ['nullable', 'array'],
  65. 'steps.*.result' => ['nullable', 'string', 'max:20000'],
  66. 'steps.*.result_chars' => ['nullable', 'integer', 'min:0'],
  67. 'steps.*.tokens_in' => ['nullable', 'integer', 'min:0'],
  68. 'steps.*.tokens_out' => ['nullable', 'integer', 'min:0'],
  69. 'steps.*.ms' => ['nullable', 'integer', 'min:0'],
  70. 'steps.*.error' => ['nullable', 'string', 'max:20000'],
  71. 'steps.*.started_at' => ['nullable', 'date'],
  72. ];
  73. }
  74. }