executor_fixtures.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. from __future__ import annotations
  2. from langchain_core.messages import AIMessage
  3. from production_build_agents.contracts.models import (
  4. CandidateArtifact,
  5. ExecutorCandidate,
  6. Finding,
  7. ArtifactBindingClaim,
  8. )
  9. from tests.support.fake_models import ToolAwareFakeChatModel
  10. DEFAULT_SOURCE_PATHS = [
  11. "$.帖子类型",
  12. "$.核心制作点[0]",
  13. ]
  14. def build_executor_candidate(
  15. *,
  16. run_id: str = "test-run",
  17. plan_id: str = "GlobalDataPlan",
  18. task_id: str = "Task1",
  19. plan_version: int = 1,
  20. deliverable_type: str = "structured_data",
  21. artifact_uri: str | None = None,
  22. expectation_id: str = "Requirement1-Expectation1",
  23. evidence_tool_call_ids: list[str] | None = None,
  24. source_paths: list[str] | None = None,
  25. ) -> ExecutorCandidate:
  26. selected_source_paths = (
  27. source_paths
  28. if source_paths is not None
  29. else DEFAULT_SOURCE_PATHS
  30. )
  31. artifacts = []
  32. findings = [
  33. Finding(
  34. statement="主视觉应保持制作表给出的统一设定",
  35. source_paths=selected_source_paths,
  36. )
  37. ]
  38. payload = {"global_constraints": ["统一主视觉"]}
  39. if deliverable_type == "image":
  40. payload = {}
  41. artifacts = [
  42. CandidateArtifact(
  43. artifact_type="image",
  44. uri=artifact_uri or "https://example.test/reference.png",
  45. description="全局视觉参考图",
  46. )
  47. ]
  48. findings = []
  49. elif deliverable_type == "video":
  50. payload = {}
  51. artifacts = [
  52. CandidateArtifact(
  53. artifact_type="video",
  54. uri=artifact_uri or "https://example.test/video.mp4",
  55. description="任务视频",
  56. )
  57. ]
  58. findings = []
  59. elif deliverable_type == "research_result":
  60. payload = {}
  61. artifacts = []
  62. findings = [
  63. Finding(
  64. statement="检索得到一条可用参考资料",
  65. source_urls=[artifact_uri or "https://example.test/source"],
  66. )
  67. ]
  68. elif deliverable_type == "reference_collection":
  69. payload = {}
  70. artifacts = [
  71. CandidateArtifact(
  72. artifact_type="reference",
  73. uri=artifact_uri or "https://example.test/reference",
  74. description="参考资料",
  75. )
  76. ]
  77. findings = []
  78. return ExecutorCandidate(
  79. schema_version="0.3",
  80. run_id=run_id,
  81. plan_id=plan_id,
  82. task_id=task_id,
  83. plan_version=plan_version,
  84. deliverable_type=deliverable_type,
  85. payload=payload,
  86. artifacts=artifacts,
  87. artifact_binding_claims=[
  88. ArtifactBindingClaim(
  89. expectation_id=expectation_id,
  90. artifact_uri=(
  91. artifacts[0].uri
  92. if artifacts
  93. else "delivery_artifact.json"
  94. ),
  95. evidence_tool_call_ids=evidence_tool_call_ids or [],
  96. )
  97. ],
  98. findings=findings,
  99. unresolved=[],
  100. summary="已完成当前 Task",
  101. )
  102. def build_executor_model(
  103. *candidates: ExecutorCandidate,
  104. ) -> ToolAwareFakeChatModel:
  105. return ToolAwareFakeChatModel(
  106. responses=[
  107. AIMessage(content=candidate.model_dump_json())
  108. for candidate in candidates
  109. ]
  110. )