feat: add trusted ticket intake backend

This commit is contained in:
hailin
2026-07-16 19:37:32 +08:00
parent b592dc219d
commit bcd6de4609
28 changed files with 1966 additions and 42 deletions

View File

@@ -196,16 +196,29 @@ def _invoke_for_step(
step: AgentRunStep,
prompt: str,
attempt_type: str,
image_parts: list[dict] | None = None,
) -> ModelInvocation:
version = run.agent_version
messages = []
if version.system_prompt:
messages.append({"role": "system", "content": version.system_prompt})
messages.append({"role": "user", "content": prompt})
user_content: str | list[dict] = prompt
if image_parts:
user_content = [{"type": "text", "text": prompt}, *image_parts]
messages.append({"role": "user", "content": user_content})
snapshot_messages = [
{"role": item["role"], "content": prompt if item["role"] == "user" else item["content"]}
for item in messages
]
invocation = ModelInvocation.objects.create(
deployment=version.model_deployment,
invocation_type="agent_step",
input_snapshot={"messages": messages, "run_id": str(run.public_id), "step": step.code},
input_snapshot={
"messages": snapshot_messages,
"image_refs": run.input_payload.get("image_refs", []) if image_parts else [],
"run_id": str(run.public_id),
"step": step.code,
},
created_by=run.created_by,
)
execute_invocation(
@@ -250,7 +263,7 @@ def _repair_output(
return invocation
def execute_agent_run(run_id: int) -> AgentRun:
def execute_agent_run(run_id: int, *, image_parts: list[dict] | None = None) -> AgentRun:
run = AgentRun.objects.select_related(
"definition",
"agent_version__model_deployment__provider",
@@ -294,7 +307,7 @@ def execute_agent_run(run_id: int) -> AgentRun:
step.input_payload = step_input
step.save(update_fields=["input_payload"])
prompt = render_prompt(binding.skill_version.prompt_template, step_input)
invocation = _invoke_for_step(run, step, prompt, "initial")
invocation = _invoke_for_step(run, step, prompt, "initial", image_parts)
if invocation.status != "succeeded":
raise AgentValidationError(invocation.error_message or "模型调用失败")
try: