Foundation And Survey Intake Agents#
These components define the agent execution contract and the first steps of most pyCSAMT workflows: parse intent, load data, and coordinate downstream processing.
BaseAgent#
BaseAgent is the shared base class for all agent classes. It resolves the
effective LLM configuration, exposes query_llm(), tracks per-call cost,
provides JSON extraction helpers, and injects pyCSAMT plotting/style helpers
so figures produced by agents remain consistent with the rest of the package.
Use it when building custom agents:
1from pycsamt.agents import BaseAgent, AgentResult
2
3class MyAgent(BaseAgent):
4 def __init__(self):
5 super().__init__("MyAgent")
6
7 def execute(self, input_data):
8 self._last_cost = 0.0
9 return AgentResult(
10 status="success",
11 summary="Custom step complete.",
12 data={"value": 1},
13 cost_estimate_usd=self._last_cost,
14 )
AgentResult#
AgentResult is the standard return object for every agent. It contains
status, summary, structured data, warnings, optional LLM interpretation, run
time, cost estimate, and failure details.
The result supports dict-like access to data:
1result = agent.execute({"path": "/data/EDIs"})
2
3if result:
4 print(result.summary)
5 print(result["sites"])
6 print(result.get("qc_table"))
7else:
8 print(result.error)
9 print(result.error_fix_hint)
ContextInputAgent#
ContextInputAgent converts natural-language workflow requests into a
structured configuration dictionary. It can call an LLM when configured, but
also includes a regex fallback for common request patterns such as loading a
path, selecting a workflow, and extracting period ranges.
Typical input keys:
Key |
Meaning |
|---|---|
|
Natural-language request. Preferred key. |
|
Alternative text keys accepted by the agent. |
Typical output keys include config, extracted path fields, workflow name,
period range, and validation warnings.
1from pycsamt.agents import ContextInputAgent
2
3agent = ContextInputAgent()
4result = agent.execute({
5 "request": "Load EDIs from /data/WILLY, QC them, period 0.001 to 10 s",
6})
7
8print(result["config"])
9print(result.llm_interpretation)
Use this agent at the start of natural-language workflows or before building
an AgentCoordinator from user text.
MTLoaderAgent#
MTLoaderAgent loads MT, AMT, or CSAMT survey data into a pyCSAMT Sites
object. It accepts a single file, a directory, a list of paths, an existing
Sites object, or an EDI collection supported by the lower-level loading
utilities.
Typical output keys:
Key |
Meaning |
|---|---|
|
Loaded |
|
Ordered station names. |
|
Number of loaded stations. |
|
Per-station loading and quality summary. |
|
Survey-level loading and quality statistics. |
1from pycsamt.agents import MTLoaderAgent
2
3result = MTLoaderAgent().execute({
4 "path": "/data/WILLY_EDIs",
5})
6
7print(result["n_stations"])
8print(result["quality_table"])
Use this agent whenever a workflow needs a validated Sites object before
QC, static-shift correction, phase analysis, or inversion preparation.
AgentCoordinator#
AgentCoordinator is not a BaseAgent subclass, but it is the central
workflow runner for explicit multi-agent pipelines. It registers ordered
steps, maps previous results into the next step with input_fn, supports
dry-run previews, and aggregates cost.
1from pycsamt.agents import AgentCoordinator, ContextInputAgent, MTLoaderAgent
2
3coord = AgentCoordinator("load_preview")
4coord.add_step("parse", ContextInputAgent())
5coord.add_step(
6 "load",
7 MTLoaderAgent(),
8 input_fn=lambda r: {
9 "path": (r["parse"].get("config") or {}).get("data_path", "")
10 },
11)
12
13result = coord.execute(
14 {"request": "Load /data/WILLY_EDIs"},
15 dry_run=True,
16)
17
18print(result["plan"])
Use the coordinator when the chain is known and should be reproducible.