How aditya-siraskar/stance works
STANCE is a local SEC-filings research copilot. Its main workflow takes an analyst’s question through entity/period scoping, plan generation and routing, then retrieves filing text for narrative answers or resolves XBRL facts for deterministic numeric answers; verification checks cited figures before the UI presents the result. A separate ingestion capability builds the filing corpus and structured fact store. The graph and README document the major stages; some ingestion and retrieval internals were not excerpted, so those links are cited to the README rather than implying inspected calls.
Main entry points: graph.py LangGraph workflow · resolver.py Fact resolution · contracts.py Typed contracts · interpret.py Numeric interpretation
Components 28
Corpus ingestion
- Filing acquisition
stance/ingest/acquire.py - Filing parsing
stance/ingest/parse.py - Section segmentation
stance/ingest/segment.py - Parent-child chunks
stance/ingest/chunk.py - Text embeddings
stance/ingest/embed.py - XBRL fact extraction
stance/ingest/facts.py - Postgres + pgvector
stance/db.py
Question workflow
- LangGraph workflow
stance/agents/graph.py - Scope resolution
stance/agents/scope.py - Question planner
stance/agents/planner.py - Deterministic router
stance/agents/router.py - Typed contracts
stance/contracts.py - Citation verifier
stance/agents/verifier.py - Model routing
stance/llm.py
Narrative retrieval
- Hybrid search
stance/retrieval/hybrid.py - Result reranking
stance/retrieval/rerank.py - Section expansion
stance/retrieval/expand.py - Narrative drafting
stance/agents/writer.py
Numeric verification
- Numeric interpretation
stance/numeric/interpret.py - Fact resolution
stance/numeric/resolver.py - Computation specs
stance/numeric/calculator.py - Spec execution
stance/numeric/executor.py - Arithmetic sandbox
stance/numeric/sandbox.py
User experience
- Streamlit UI
apps/ui/app.py - Pipeline display
apps/ui/pipeline_viz.py - Evaluation driver
eval/run_eval.py
Other components
- Analyst
- SEC EDGAR
Connections 39
- Analyst → Streamlit UI: asks question
README.md - Streamlit UI → LangGraph workflow: invokes / streams
apps/ui/app.py - LangGraph workflow → Scope resolution: resolves scope
stance/agents/graph.py - LangGraph workflow → Question planner: builds plan
stance/agents/graph.py - LangGraph workflow → Deterministic router: routes plan
stance/agents/graph.py - LangGraph workflow → Hybrid search: searches text
stance/agents/graph.py - LangGraph workflow → Result reranking: reranks candidates
stance/agents/graph.py - LangGraph workflow → Section expansion: expands results
stance/agents/graph.py - LangGraph workflow → Narrative drafting: drafts narrative
stance/agents/graph.py - LangGraph workflow → Numeric interpretation: answers numeric steps
stance/agents/graph.py - LangGraph workflow → Citation verifier: verifies draft
stance/agents/graph.py - LangGraph workflow → Typed contracts: uses typed state
stance/agents/graph.py - Question planner → Model routing: requests completion
stance/agents/planner.py - Narrative drafting → Model routing: requests completion
stance/agents/writer.py - Numeric interpretation → Fact resolution: resolves facts
stance/numeric/interpret.py - Numeric interpretation → Computation specs: builds computation
stance/numeric/interpret.py - Numeric interpretation → Spec execution: executes spec
stance/numeric/interpret.py - Computation specs → Typed contracts: emits spec
stance/numeric/calculator.py - Spec execution → Fact resolution: loads operands
stance/numeric/executor.py - Spec execution → Arithmetic sandbox: runs operation
stance/numeric/executor.py - Citation verifier → Fact resolution: rechecks citations
stance/agents/verifier.py - Scope resolution → Typed contracts: produces scope
stance/agents/scope.py - Question planner → Typed contracts: produces plan
stance/agents/planner.py - Deterministic router → Typed contracts: reads plan
stance/agents/router.py - Streamlit UI → Pipeline display: renders trace
apps/ui/app.py - Streamlit UI → Evaluation driver: runs evaluation
apps/ui/app.py - Evaluation driver → LangGraph workflow: evaluates questions
eval/run_eval.py - Evaluation driver → Citation verifier: runs injection check
eval/run_eval.py - Evaluation driver → Fact resolution: looks up test fact
eval/run_eval.py - SEC EDGAR → Filing acquisition: supplies filings
README.md - Filing acquisition → Filing parsing: ingestion sequence
README.md - Filing parsing → Section segmentation: ingestion sequence
README.md - Section segmentation → Parent-child chunks: ingestion sequence
README.md - Parent-child chunks → Text embeddings: ingestion sequence
README.md - Text embeddings → Postgres + pgvector: stores vectors
README.md - Filing acquisition → XBRL fact extraction: extracts XBRL facts
README.md - XBRL fact extraction → Postgres + pgvector: stores facts
README.md - Hybrid search → Postgres + pgvector: searches chunks
README.md - Fact resolution → Postgres + pgvector: queries facts
stance/numeric/resolver.py