feat(proxy-clients): pydantic-ai / mem0 / graphiti integration layer - #1202
Open
RainGodPRC wants to merge 2 commits into
Open
feat(proxy-clients): pydantic-ai / mem0 / graphiti integration layer#1202RainGodPRC wants to merge 2 commits into
RainGodPRC wants to merge 2 commits into
Conversation
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Three complementary subsystems wired through a shared proxy-client layer, all opt-in via environment variables (zero regression when disabled). Shared layer (tradingagents/llm_clients/proxy_clients.py): - resolve_gateway_token() extracts the cc-switch Bearer token from env or a running Claude Code process (the proxy rejects x-api-key) - make_anthropic_client() with auth_token (Bearer, not x-api-key) - Local HuggingFace embedder (proxy serves no /v1/embeddings) - Factory helpers for pydantic-ai Agent, mem0 Memory, graphiti Graphiti pydantic-ai backend (structured.py): - Optional path in invoke_structured_or_freetext, enabled by TRADINGAGENTS_USE_PYDANTIC_AI=1, with a validation-retry loop that the legacy one-shot fallback lacked — preserves BUY/SELL/HOLD signals - Trader, Portfolio Manager, Research Manager pass schema+instructions mem0 decision memory (mem0_bridge.py + trading_graph._run_graph): - remember_decision() / recall_relevant() back the Portfolio Manager - Semantic cross-ticker recall complements the ticker-matched markdown log - Enabled by TRADINGAGENTS_MEM0_ENABLED=1 graphiti Winterfell import (scripts/import_winterfell_to_graphiti.py): - Imports Decisions/Collisions/Analysis/Insights as temporal episodes - reference_time from frontmatter date/created - Monkey-patches graphiti search to skip Kuzu fulltext/vector index bugs (Kuzu backend is deprecated in graphiti for this reason) Tests: three smoke tests + mem0 bridge integration + trader pydantic-ai integration + end-to-end (graphiti ingest -> pydantic-ai decision -> mem0 recall). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
RainGodPRC
force-pushed
the
feat/proxy-clients-pydantic-ai-mem0-graphiti
branch
from
August 8, 2026 09:30
68700b3 to
573da75
Compare
Wrap each provider's sync _generate / async _agenerate with tenacity exponential backoff so a saturated inference gateway (e.g. local proxy at 127.0.0.1:15721 returning HTTP 529) no longer exhausts the SDK's built-in retries and aborts the whole run with 'Service was busy'. Only transient errors (429 / 5xx / 529 / timeouts / connection drops) are retried; auth, validation, and not-found errors fail fast. Retry budget is tunable via TRADINGAGENTS_LLM_MAX_ATTEMPTS / TRADINGAGENTS_LLM_RETRY_MAX_WAIT. Co-Authored-By: WorkBuddy <workbuddy@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Three complementary subsystems wired through a shared proxy-client layer. All opt-in via environment variables — zero regression when disabled (the existing LangGraph pipeline is unchanged unless
TRADINGAGENTS_USE_PYDANTIC_AI=1/TRADINGAGENTS_MEM0_ENABLED=1are set).Shared layer (
tradingagents/llm_clients/proxy_clients.py)resolve_gateway_token()— extracts the cc-switch Bearer token from env or a running Claude Code process (the proxy at127.0.0.1:15721rejectsx-api-key, requiresAuthorization: Bearer)make_anthropic_client()— auth_token-based (Bearer, not x-api-key)/v1/embeddings; mem0 + graphiti both use this local fallbackmake_pydantic_ai_agent(),make_mem0_memory(),make_graphiti()pydantic-ai backend (
structured.py)Optional path in
invoke_structured_or_freetext, enabled byTRADINGAGENTS_USE_PYDANTIC_AI=1. Adds a validation-retry loop (the model is prompted to correct malformed output) that the legacy one-shot fallback lacked — preserves structured signals (BUY/SELL/HOLD, rating) that currently get lost when structured output fails and silently degrades to free text.Trader, Portfolio Manager, Research Manager pass
schema=+instructions=so they benefit when the flag is on.mem0 decision memory (
mem0_bridge.py+trading_graph._run_graph)Mem0Bridgeprovidesremember_decision()/recall_relevant(). Wired into_run_graph: semantic recall of past decisions is appended topast_contextbefore the pipeline runs; the completed decision is stored after. Cross-ticker recall ("I've seen this Fed-pivot pattern before") complements the ticker-matched markdown log. Enabled byTRADINGAGENTS_MEM0_ENABLED=1.graphiti Winterfell import (
scripts/import_winterfell_to_graphiti.py)Imports Decisions/Collisions/Analysis/Insights Markdown as temporal episodes, using frontmatter
date/createdasreference_time. Monkey-patches graphiti's search functions to skip Kuzu's broken fulltext/vector indices (Kuzu is deprecated in graphiti for this reason) — ingestion works on Kuzu, but full dedup/temporal invalidation requires Neo4j/FalkorDB.Tests
test_trader_pydantic_ai_integration.py— Trader node produces structured proposal via pydantic-aitest_mem0_bridge_integration.py— cross-ticker semantic recalltest_e2e_integration.py— full loop: graphiti ingest → pydantic-ai decision → mem0 recallVerification
All tests pass against the local cc-switch proxy. No regression in the existing 492-test suite (imports verified, flags default off).
Known limitations
ccs-gateway token)trading_graph.pyalso carries a pre-existing_fetch_returnssignature refinement that was in the working tree; it's logically intertwined with the mem0 bridge in_run_graph🤖 Generated with Claude Code