Parse a raw ``agent_reference`` value from a profile JSON into an AgentReference. ``base_dir`` is the directory the profile file lives in; a relative ``source`` resolves against it (falling back to the current working directory).
(spec: object, base_dir: str | Path | None = None)
| 54 | |
| 55 | |
| 56 | def parse_agent_reference(spec: object, base_dir: str | Path | None = None) -> AgentReference: |
| 57 | """Parse a raw ``agent_reference`` value from a profile JSON into an AgentReference. |
| 58 | |
| 59 | ``base_dir`` is the directory the profile file lives in; a relative ``source`` |
| 60 | resolves against it (falling back to the current working directory). |
| 61 | """ |
| 62 | if spec is None or spec == "default": |
| 63 | return DEFAULT_AGENT_REFERENCE |
| 64 | if not isinstance(spec, dict) or "source" not in spec: |
| 65 | raise SystemExit('agent_reference must be "default" or an object with a "source" field') |
| 66 | |
| 67 | data = cast("dict[str, Any]", spec) |
| 68 | base = Path(base_dir) if base_dir else Path.cwd() |
| 69 | source = Path(data["source"]) |
| 70 | if not source.is_absolute(): |
| 71 | source = base / source |
| 72 | source = source.resolve() |
| 73 | |
| 74 | if source.is_dir(): |
| 75 | return AgentReference(kind="dir", source=source, entrypoint=data.get("entrypoint")) |
| 76 | if source.is_file(): |
| 77 | return AgentReference(kind="file", source=source) |
| 78 | raise SystemExit(f"agent_reference source not found: {source}") |
| 79 | |
| 80 | |
| 81 | def resolve_agent_reference(ref: AgentReference, task_layout: TaskLayout) -> ResolvedAgentReference: |