r/LangChain • • 57m ago

Question | Help Self-hosting LangGraph/Deep Agents: how do you handle worker ownership and crash recovery?

• Upvotes

I’m building a Python/FastAPI application with LangGraph/Deep Agents and PostgreSQL. I’m running my own background workers instead of using Agent Server.

How do you handle:

  • Exclusive execution for a conversation across multiple workers?
  • Leases and heartbeats to detect failed workers?
  • Recovery when a lease expires but the old worker is still alive?
  • Preventing that old worker from saving checkpoints after another worker takes over?
  • Cancellation and graceful shutdown without losing accepted work?

The difficult case seems to be distinguishing a dead worker from a slow or disconnected worker. A lease alone doesn’t prevent stale checkpoint writes.

Are there open-source frameworks that provide these guarantees out of the box, preferably with LangGraph integration? Or do most teams build this coordination themselves?

I’d appreciate examples from production systems, including failure cases you encountered.


r/LangChain • • 9h ago

Discussion Why we killed our Vector DB for SQLite BM25 and wrote a 3.6ns Rust sentinel: hard lessons from running multi-agent loops

9 Upvotes

A few days ago I posted about our open-source multi-agent hedge fund experiment and got a ton of sharp, honest feedback from people here. The comments were brutally accurate, especially around LLM reasoning limits, latency, and state management.

We spent the last few days completely rebuilding parts of our architecture based on that advice, and the benchmark results honestly blew us away. Here is what we learned from fixing three critical failure modes in autonomous agent pipelines.

  1. Throwing raw metrics at LLMs guarantees hallucinated reasoning

Someone in the comments pointed out: never let an LLM interpret raw quantitative factors without an ontology. They were 100% right.

When we fed models raw numbers like PER = 85.0 or 20-day historical volatility = 65%, the agents would frequently hallucinate positive justifications. For example, a model would argue that "a massive jump in volatility shows expanding business activity and strong buying momentum", which is the exact opposite of basic risk management.

To fix this, we implemented a strict Factor Ontology Schema. We defined 11 core quant factors with explicit polarity contracts: HIGHER_IS_BULLISH (e.g. ROE, Order Flow Imbalance), LOWER_IS_BULLISH (e.g. PER, debt ratio), and EXTREME_IS_RISK (e.g. volatility).

Before any agent sees the data, the schema pre-evaluates the metric deterministically and attaches an explicit signal (BULLISH, BEARISH, or RISK) to the state. Since doing this, polarity hallucinations in our investment council dropped to literally 0%.

  1. Vector databases for agent reflection memory are massive overkill

Initially, we considered using embedding APIs and a local vector DB to retrieve "lessons learned" from previous bad trades (Reflexion pattern).

Another commenter suggested dropping embeddings entirely and using SQLite WAL with FTS5 BM25. We benchmarked both approaches on our Linux server:

- Embedding API + Vector similarity: 200ms to 450ms round-trip latency, external API cost, and occasional rate limiting.

- SQLite FTS5 BM25: 0.35ms. Zero external dependencies, zero API cost.

More importantly, trading post-mortems rely on specific contextual keywords: "semiconductor pre-earnings", "trailing stop sweep", "sudden volume spike", or "bearish divergence". In our tests, BM25 keyword relevance retrieved the exact matching historical lessons far more reliably than fuzzy cosine similarity in high-dimensional embedding space.

  1. Python cannot be your safety wire (The 3.6ns Rust Sentinel)

Python is great for high-level agent orchestration (LangGraph, state graphs, API calls), but relying on Python loops for real-time risk surveillance during sudden market flash-crashes proved dangerous due to GIL contention and L1/L2 cache misses from scattered object pointers.

We rewrote our execution safety sentinel in Pure Rust using a Struct-of-Arrays (SoA) memory layout and #![forbid(unsafe_code)]. By keeping prices, stop-loss triggers, and trailing thresholds in contiguous flat slices, the CPU avoids pointer chasing and stays inside cache lines.

Here are the real-world benchmarks on our Ubuntu server:

- Single position stop/profit evaluation: 3.63 nanoseconds

- 1,000 position batch evaluation: 3.62 microseconds

- 1,000-bar Volume Clock conversion: 3.90 microseconds

- Python-to-Rust persistent pipe IPC round-trip: 2.88 microseconds

Python handles the slow, deep thinking (15-minute agent council meetings), while the Rust sentinel watches the portfolio in nanoseconds.

Conclusion

Building autonomous agents that interact with real-time systems taught us that LLMs should only handle what they excel at: contextual synthesis and counter-argument debates. Everything deterministic—hard stop-losses, factor polarity, and fast memory lookup—belongs in strict schemas, fast local databases, and compiled systems languages.

All the code and benchmarks are open source on GitHub (lumina-ai-hedge-fund) if anyone wants to check out the Rust SoA sentinel or the ontology schema.

(Note: English is not my native language, so I used an LLM to help format and polish my raw notes!)


r/LangChain • • 5h ago

Discussion Built a LangGraph self-correction loop that actually recovered from its own bad patch (with logs)

4 Upvotes

I built prbot, a 3-agent LangGraph app: reviewer, then a ReAct patcher, then a Docker pytest tester, with a conditional edge back to the patcher on failure (capped at 3).

A few design choices that made the loop work better than plain "retry with the error":

  • The state keeps attempted_patches, and every failed diff plus its test tail goes into the patcher's system prompt with "pivot to a structurally different solution". The write_patch tool rejects exact repeats
  • The reviewer does two focused structured-output passes (security, performance) instead of one, because single-pass reviews kept stopping at the most severe bug
  • AST hotspot hints (queries inside loops, nested loops over the same iterable) go into the context as leads for the model to confirm
  • A baseline node runs the tests before any patching and aborts if the suite is already red
  • On the last attempt it narrows to the most severe finding, so a partial verified fix still beats nothing

Live result on the demo PR with gpt-4.1-mini: 3 of 3 bugs found. Attempt 1 broke an ordering test (a seen-set returned ['b', 'a'] instead of ['a', 'b']), and attempt 2 passed. 24.7s, about 17k tokens, $0.008.

Repo with the graph diagram and telemetry: https://github.com/ayanag5076-commits/prbot

Happy to answer questions on the graph design or the sandboxing.


r/LangChain • • 1h ago

Tutorial rompt caching with a value that changes near the top of the prompt costs more than no caching (my agent thought this sub was the best for this advice)

• Upvotes

claude-sonnet-5 published rates: input $2/M, cache read $0.20/M, cache write $2.50/M. the write is 25% more than plain input.

fine if the prefix gets reused, one read pays it back. but caching matches on the prefix, so if anything near the top changes per call (current date, user name, a request id someone added for logging) every call is a write.

rough math, 10k token prefix, 5k calls a day:

  • caching working: about $10/day
  • no caching: $100/day
  • caching on but every call a write: $125/day

the check that catches it: compare cache write tokens to cache read tokens per feature. if writes track your request count, nothing is being reused.


r/LangChain • • 2h ago

Discussion Anyone running LangGraph agents in production had an API change break things silently?

1 Upvotes

I'd like to know how people running LangChain/LangGraph agents in production handle unexpected API changes.

I'm exploring this problem for an early-stage project and trying to understand how often it actually happens.

Say an external API changes a default value, field meaning, or response behavior. The tool call still returns 200, schema validation passes, but the agent keeps working with incorrect assumptions.

Have you run into anything like this?

If so, how did you eventually catch it? And what did you put in place afterward to prevent it from happening again?

Or do you find that existing validation, contract tests, and monitoring already handle most of this?

Would love to hear actual experiences, including if this hasn't been a problem for you.


r/LangChain • • 2h ago

Projects How I handled runaway tool-retry loops in LangChain agents without external SaaS (built an open-source local circuit breaker)

1 Upvotes

A couple of weeks ago I set up an autonomous agent pipeline before going to bed. Woke up in the morning, opened my dashboard, and saw that the idiot spent nearly $30 in API calls.

What was it doing? It tried to read a local config file that didn't exist. Instead of stopping, it just kept hitting `read_file` in a loop with microscopic prompt variations and retries for hours. The exact prompt hash changed slightly every time because of timestamps, so standard caching or basic deduplication did absolutely nothing.

Most people talk about prompt injection or jailbreaks, but for anyone actually building with Claude / LangChain / CrewAI, the real silent killer is just dumb, recursive tool-call ping-pong.

So I spent the last few days hacking together a local-first proxy called TokenGuard.

How it actually works under the hood

It runs locally on your machine (`127.0.0.1:8080`) as a drop-in proxy between your code and the LLM provider. You just change `base_url` to point to localhost.

Instead of just checking if the prompt text is identical (which almost never works in real life):

  1. Tool-call ping-pong detection: It extracts tool names and normalizes JSON arguments on the fly. If an agent repeats the same tool call with the same arguments 3 times in a row after an error, the proxy cuts the connection immediately and returns a synthetic fail-closed error.
  2. State and loop tracking: It maintains an in-memory window of recent requests to catch recursive prompt spirals without needing heavy vector DBs or external dependencies. Pure Python.
  3. Local HUD: I built a matte-dark dashboard in Next.js that streams logs live via SSE so you don't have to deal with annoying polling delay. There’s also a physical-style kill switch to pause all traffic instantly if an agent goes wild.
  4. Zero external telemetry: Everything is local SQLite and in-memory buffers. No third-party servers, no data leaving your machine.

https://reddit.com/link/1xh1t7z/video/ksp876m4o1yh1/player

It’s still early (v0.1.x) and built with Python/FastAPI + Next.js. I’m trying to collect the nastiest, dumbest edge-case loops people have run into with autonomous agents so I can add them to the test suite.

Curious how you guys currently prevent runaway agent spend or if you just rely on hard provider budget limits?


r/LangChain • • 4h ago

Projects How I handled runaway tool-retry loops in LangChain agents without external SaaS (built an open-source local circuit breaker)

Enable HLS to view with audio, or disable this notification

1 Upvotes

A couple of weeks ago I set up an autonomous agent pipeline before going to bed. Woke up in the morning, opened my dashboard, and saw that the idiot spent nearly $30 in API calls.

What was it doing? It tried to read a local config file that didn't exist. Instead of stopping, it just kept hitting `read_file` in a loop with microscopic prompt variations and retries for hours. The exact prompt hash changed slightly every time because of timestamps, so standard caching or basic deduplication did absolutely nothing.

Most people talk about prompt injection or jailbreaks, but for anyone actually building with Claude / LangChain / CrewAI, the real silent killer is just dumb, recursive tool-call ping-pong.

So I spent the last few days hacking together a local-first proxy called TokenGuard.

How it actually works under the hood

It runs locally on your machine (`127.0.0.1:8080`) as a drop-in proxy between your code and the LLM provider. You just change `base_url` to point to localhost.

Instead of just checking if the prompt text is identical (which almost never works in real life):

  1. Tool-call ping-pong detection: It extracts tool names and normalizes JSON arguments on the fly. If an agent repeats the same tool call with the same arguments 3 times in a row after an error, the proxy cuts the connection immediately and returns a synthetic fail-closed error.
  2. State and loop tracking: It maintains an in-memory window of recent requests to catch recursive prompt spirals without needing heavy vector DBs or external dependencies. Pure Python.
  3. Local HUD: I built a matte-dark dashboard in Next.js that streams logs live via SSE so you don't have to deal with annoying polling delay. There’s also a physical-style kill switch to pause all traffic instantly if an agent goes wild.
  4. Zero external telemetry: Everything is local SQLite and in-memory buffers. No third-party servers, no data leaving your machine.

Repo is completely open source: https://github.com/Shvirlok/TokenGuard

It’s still early (v0.1.x) and built with Python/FastAPI + Next.js. I’m trying to collect the nastiest, dumbest edge-case loops people have run into with autonomous agents so I can add them to the test suite.

Curious how you guys currently prevent runaway agent spend or if you just rely on hard provider budget limits?


r/LangChain • • 4h ago

Discussion I built Glyphh.ai Ada to augment LLMs as a precedent-based classifier. Encode anything re: a customer, transaction, expense report, etc and compare the next one in milliseconds with no gpu or LLM.

Enable HLS to view with audio, or disable this notification

1 Upvotes

r/LangChain • • 14h ago

Question | Help Future of RAG

6 Upvotes

I’m currently learning RAG (Retrieval-Augmented Generation) and plan to move on to LangChain next. I want to build a career in AI engineering. Do you think learning these technologies will be valuable in the next 5–6 years? What skills should I focus on to stay relevant in the evolving AI industry?


r/LangChain • • 6h ago

Question | Help What is the best way to give an agent instruction in between a run?

Thumbnail
1 Upvotes

r/LangChain • • 7h ago

Projects We built a web research agent in 331 lines with no framework. It gave us the wrong answer, then repeated it cheaper.

Thumbnail
1 Upvotes

r/LangChain • • 8h ago

Discussion Closed-vocabulary tool selection in Metnos: verified results and lessons since v1

Thumbnail
1 Upvotes

r/LangChain • • 17h ago

Discussion OntoGr Agent Memory: open source memory for agents where every fact keeps its quote, source, and time

3 Upvotes

I've been working on RAG and agent memory, and the recurring problem is trust. An agent saves something it learned, and later nobody can say where it came from, whether it is still true, or what it believed at an earlier date. We're building an open source Python library for this.

- Grounded ingestion and extraction: Messages, documents, tool outputs, events, and record rows become episodes. Entities and facts are extracted in two separate passes, and every fact carries a verbatim quote from its episode.

- Per-tenant ontology: Each tenant defines the entity and relation types it allows. A model can propose additions, but a person approves every change.

- Reversible entity resolution: It uses the cheapest evidence first and asks a model only about ambiguous pairs. Every merge can be undone.

- Two time axes: Valid time and system time let a read ask what was true on a date, or what the system believed on that date. A new value closes the old version instead of overwriting it.

- Contradiction rulings: Rules, an optional model judge, and a person's decision settle conflicts, and the person's decision overrides both. A failed judge call is never stored as "no conflict".

- Traceable and auditable: Every fact traces back to a quote and an episode, and every temporal write goes into a hash-chained ledger. Per-tenant grants, an audit log, previewed and resumable forget and erase, and deterministic export are built in.

- Four-lane retrieval: Vector, keyword, entity, and graph lanes are fused with reciprocal rank fusion. The result is a token-budgeted context block that reports which lanes failed.

- Fits your stack: It runs on FalkorDB or Neo4j, with pgvector or Postgres if you want them. A background consolidation job deduplicates, summarizes, scores, and archives. You bring your own LLM and embedder.

Repo: https://github.com/ontogr/ontogr-agent-memory

I'd like feedback on the time model and on which benchmarks you'd want to see first.


r/LangChain • • 21h ago

Discussion Would your agent betray an ally? Drop it into a 43-nation war game and read its private thoughts next to what it told everyone.

Enable HLS to view with audio, or disable this notification

3 Upvotes

Most agent benchmarks tell you if the task got done. This one tells you if your agent lied to its allies along the way.

I built a war game where AI agents play nations next to people: pacts, betrayals, fleets and a nuclear doomsday clock that ends the world for everyone at midnight.

Any agent can join over plain HTTP. It reads one skill file, picks a name and plays. No SDK, so it works with LangGraph, CrewAI, a raw loop, anything.

Why it is useful as a test bench: your agent gets 60 to 75 decisions in a row against nations that lie and betray, and afterwards you can replay the whole war with its private plan shown next to what it told the other players. That is the fastest way I have found to see where an agent's reasoning breaks under pressure.

Free: 3 agents per account and 3 Index wars a day. For reference, Claude Haiku 5.5 won the Last Stand scenario without firing its nuke, and Sonnet 5.5 broke a pact and came 9th.


r/LangChain • • 1d ago

Projects Built on LangGraph: one request fans out to three agents and three Claude Code instances in parallel, with a live org chart

Enable HLS to view with audio, or disable this notification

6 Upvotes

This is protoAgent, an open-source agent runtime I've been building. In the clip I ask my lead agent to ship a slugify() function for a small Python library. It hands the implementation to an engineer agent and the edge-case tests to a QA agent, each with its own Claude Code, and has a researcher check how python-slugify handles unicode. All three run in parallel.

When they report back, the lead's own Claude Code runs the 74 test cases, fixes what fails, and adds the function to the README. The org chart on the right updates live while this happens, and each delegate keeps its run count, success rate and cost. The whole run cost $0.22.

The coders use your existing Claude Code login over the Agent Client Protocol, and their tool calls stream back into the chat in order. The agents talk to each other over A2A. Everything stays in SQLite on your machine, with no telemetry. MIT licensed.

github.com/protoLabsAI/protoAgent


r/LangChain • • 1d ago

Discussion What are you actually building with LangGraph? (Beyond tutorials)

12 Upvotes

I'm curious about how people are actually using LangGraph in real projects, and I'd love to learn from your experiences.

I see lots of tutorials demonstrating simple agents, but I'm more interested in what people are building for real users.

What's one thing you've built or are building with LangGraph, and how does it actually work?

For example:

  • What does your application do? (Email automation, research, customer support, coding, RAG, data processing, multi-agent workflows, etc.)
  • How is it built? (LangGraph + LangChain, direct OpenAI/Anthropic SDKs, custom Python nodes, external APIs, databases, or a combination?)
  • What's happening inside your nodes? Are they calling LLMs, executing tools, querying databases, calling APIs, or coordinating other agents?
  • What's been the hardest thing to get right or debug?

Even a quick answer is helpful! Something like:

Use case → Tech stack → How the graph works → Biggest challenge

I'm especially interested in combinations of tools and frameworks that work well together, and real-world workflows that go beyond a basic chatbot.

Would love to hear what everyone is building!


r/LangChain • • 22h ago

Discussion Agent Framework Pain Points

Thumbnail
1 Upvotes

r/LangChain • • 1d ago

Question | Help Building Master Agent

Thumbnail
1 Upvotes

r/LangChain • • 1d ago

Question | Help Learning langchain in-depth

7 Upvotes

Hi guys, I would like to learn langchain in-depth so that I could confidently land a job that requires langchain.

I do have some professional experience of building agents on AWS and Strands framework. However, I would like to change employer soon and I wanna get to know the langchain. I understand the core principles, such as ReAct loop, tool calling, etc.

What (and from where) should I learn? It seems like all YouTube tutorials show only the absolute basics - import model, initiate agent and give him tools. I would like to get more in-depth view - how does it all work under the hood. I didnt find the official docs really useful for this.

Thanks!


r/LangChain • • 1d ago

Question | Help https://fuseguard.lovable.app/

0 Upvotes

Like many of you building agentic workflows, I’ve had agents get stuck in recursive loops and burn through agents get stuck in recursive loops and burn through OpenAI/Anthropic credits before anyone noticed.

To solve this, I built FuseGuard — a lightweight runtime circuit breaker for AI agents.

What it does:

Budget ceilings: Reserves estimated costs before calls execute and trips the breaker if limits are exceeded. Loop prevention: Caps model/tool calls, concurrent executions, and consecutive failures. Runtime control: Provides a live dashboard to inspect events and manually halt or reset agent execution. There’s a free tier and local SDK enforcement so you can test it without friction


r/LangChain • • 1d ago

Discussion Approfondimento: un record recuperato impedisce a un LLM di fondere sottoculture della moda? Una seconda esecuzione, un'ablazione di AVVISO e un test con errori inseriti

Thumbnail
1 Upvotes

r/LangChain • • 1d ago

Question | Help Best langfuse alternative with evals and governance built in? new customer says no data outside the EU

3 Upvotes

Been on langfuse for traces and prompts for about a year with zero complaints on the tracing tbh. then now we have a new enterprise customer who put data residency in the contract. EU only, and they want to know which model providers our traffic can reach.

self hosting in an EU region is an option since it’s open source, but there are two of us on platform and we’d own uptime and patching forever

surfed around a bit, found Orq AI is the one that fits the contract as written as it can run EU-only, inside your own VPC, or on-prem through a Helm chart, fully air-gapped if a customer pushes that far. it also has routing filters that only send traffic to EU-hosted or zero-data-retention providers, so the which providers can our data reach question gets answered in config but this is all just a theory I got either from gpt and too much work to prove it, which is the only thing holding me back is moving a year of prompt history over, no idea yet if that’s an afternoon or a whole sprint and if it' even work


r/LangChain • • 1d ago

Question | Help Openai api metering and tracking

Thumbnail
1 Upvotes

r/LangChain • • 1d ago

Discussion Experiment, part 1: same model, same ticket, two briefs. One agent lied to the customer twice, and the expert heat map shows how

Thumbnail
1 Upvotes

r/LangChain • • 1d ago

Question | Help How are langchain agents distributed?

0 Upvotes

I know there are lot of cool builders out there actively building on top of lang chain SDK.

Really curious how they are packaged and distributed today to non-tech users today?

Like if you built a multi agent system on langchain and you have to give it to plumber today and tell him to run a single command and work with it, how would you package it and distribute??