DEV Community

Cover image for I Gave an AI Agent Access to External Services — Here’s What Broke
techwanderer
techwanderer

Posted on

I Gave an AI Agent Access to External Services — Here’s What Broke

I asked an AI agent to analyze 30 days of Ethereum data using an external market-data service. The workflow sounded trivial:

discover → approve → call API → chart → summarize
Enter fullscreen mode Exit fullscreen mode

It wasn’t.

1. Tool access did not mean executable access

The agent found the correct endpoint, but the endpoint required a paid wallet flow that was not available in the runtime. Discovery succeeded; execution failed.
The fix was to separate capability discovery from authorization. In this experiment, Anvita Flow exposed the service scope and per-call price, while execution only continued after a human approved the specific call.

2. A successful response was not trustworthy data

The call returned 721 hourly observations. It also returned two trading-volume values near 1e19—obvious outliers compared with the rest of the series.
If we had rendered the JSON directly, the volume chart would have been useless. We kept the raw values for auditability, flagged them, and excluded them from robust volume statistics.

fetch → validate schema → check units/ranges
      → flag anomalies → compute → render
Enter fullscreen mode Exit fullscreen mode

3. “30 days” had a boundary problem

The final observation arrived at 07:44 UTC, so the last day was incomplete. Comparing it with a full UTC day would distort daily volume and return calculations.
Every report now carries its exact sample window, timezone, observation count, and incomplete-period warning.

4. Correlation tried to become causation

The agent aligned price moves with ETF flows and policy events. But one policy announcement occurred after the dataset ended. Without an explicit cutoff check, it could have become a convincing—but impossible—explanation.
Event enrichment must obey:

event.timestamp <= dataset.cutoff
Enter fullscreen mode Exit fullscreen mode

What the pipeline produced

After validation, ETH showed a +26.23% 30-day return, but a -4.47% seven-day return and an 8.71% pullback from the period high. Hourly data exposed a strong repricing followed by weakening short-term momentum—detail hidden by a simple start/end comparison.
My takeaway: giving an agent external-service access is the easy part. Production reliability comes from approval boundaries, schema validation, anomaly handling, temporal checks, and preserving the raw response for review.

Top comments (1)

Collapse
 
baumgaerben profile image
baumgaerben •

Thấy mình trong câu chuyện này. Lần đầu hook agent vào API on-chain (Alchemy/QuickNode) cũng nghĩ "chỉ cần cho key, để nó tự query". Kết quả: burst request.trigger rate-limit 429, response format đổi giữa v1/v2 không báo trước, block reorg làm dữ liệu ngày hôm qua khác hôm nay — agent vẫn tự tin hallucinate số liệu.

Ba thứ giúp đỡ thực sự:

  1. Idempotency key trên mọi call ghi (cache/write DB) — retry an toàn khi network glitch.
  2. Schema contract (Zod/JSON Schema) validate response trước khi feed vào LLM, fail fast thay vì downstream debug.
  3. Deterministic snapshot: pull dữ liệu vào object store (Parquet/JSONL) versioned theo block height, agent chỉ đọc snapshot — tách biệt "data freshness" khỏi "reasoning quality".

Còn về cost: cache TTL theo epoch (7200 blocks) thay vì wall-clock, tiết kiệm ~60% call khi agent lặp lại query tương tự trong session.

Bạn có log pattern nào để detect "silent data drift" (API trả 200 nhưng field quan trọng null/missing) không? Hay chỉ頼 vào eval set cuối chuỗi? PS: the tool I meant is on labagent .tech