DeepSeek-native agent framework with production-grade reliability โ JSON repair, hybrid thinking, cache stabilization, circuit breaker.
Project description
SeekFlow
๐ฅ DeepSeek-native ย |ย โก Lightweight (6 deps) ย |ย ๐ก๏ธ Production-grade reliability
SeekFlow is the only agent framework architected around DeepSeek's actual behavior โ thinking mode, prompt caching, JSON repair, FIM. Not a generic OpenAI wrapper with DeepSeek as an afterthought.
Why SeekFlow over LangChain or CrewAI for DeepSeek?
| SeekFlow | LangChain | CrewAI | |
|---|---|---|---|
| DeepSeek thinking management | Auto-detect + budget | Manual extra_body |
Not supported |
| JSON repair | 8-rule state machine | None | None |
| Prompt cache stabilization | CacheStabilizer (90%+ hit) | None | None |
| Circuit breaker | 3-state | None | None |
| FIM (Fill-in-the-Middle) | Built-in | None | None |
| Balance/cost tracking | Real-time cache-aware | Manual | Manual |
| Dependencies | 6 | 40+ | 30+ |
Benchmark: 48 runs, 3 rounds ร 4 scenarios, blind judge (deepseek-v4-pro)
| Framework | Quality | Tokens/task | Cost/task | Time | Cache |
|---|---|---|---|---|---|
| SeekFlow Fast | 8.7 | 8,688 | CNY0.00108 | 49s | 91% |
| SeekFlow Stable | 8.8 | 12,945 | CNY0.00167 | 72s | 64% |
| LangChain | 8.8 | 10,231 | CNY0.00120 | 59s | 90% |
| CrewAI | 8.7 | 17,414 | CNY0.00149 | 72s | 90% |
SeekFlow Fast: 15% fewer tokens, 10% lower cost than LangChain. SeekFlow Stable: tied for #1 quality with deep reasoning throughout.
| Scenario | SeekFlow Fast | SeekFlow Stable | LangChain | SeekFlowไผๅฟ |
|---|---|---|---|---|
| ้่ๅๆ | 8.4 | 8.5 | 8.8 | LangChainๅพฎๅผฑ้ขๅ |
| ไพๅบ้พ | 8.4 | 8.7 | 9.1 | LangChain web_searchไผๅฟ |
| ไปฃ็ ๅฎก่ฎก | 9.1 | 8.9 | 8.7 | SeekFlow 2x tokenๆ็ |
| ็ ็ฉถ็ปผๅ | 8.9 | 9.2 | 8.6 | SeekFlow Stableๆพ่้ขๅ |
Quick Start
pip install seekflow
export DEEPSEEK_API_KEY="sk-..."
from seekflow import tool, ToolRuntime
@tool
def get_weather(city: str) -> dict:
"""Get current weather for a city."""
return {"city": city, "temperature": 22, "condition": "sunny"}
@tool
def calculate(expression: str) -> str:
"""Safely evaluate a math expression using AST whitelist."""
...
runtime = ToolRuntime(tools=[get_weather, calculate])
result = runtime.chat(
model="deepseek-chat",
messages=[{"role": "user", "content": "ๅไบฌๅคฉๆฐ๏ผ็ฎไธไธ (8630-3120)/8630"}],
)
print(result.final)
Agent mode (role/goal/backstory + autonomous tool use):
from seekflow import DeepSeekAgent
from seekflow.agent.presets import financial_analyst
agent = financial_analyst(api_key="sk-...")
agent.add_tool(get_weather)
result = agent.run("ๅๆๅไบฌๅคฉๆฐๅฏนๆ่ต็ๅฝฑๅ")
print(result.final_output) # structured investment memo
Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Agent Layer Agent / Crew / Task / Graph โ
โ Presets / Memory / Checkpoint โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Runtime chat() / chat_stream() โ
โ Hybrid thinking / Cache โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Reliability Retry + CircuitBreaker โ
โ ToolCache (LRU+TTL) โ
โ Context window management โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Tool System @tool โ Schema โ Registry โ
โ Executor (repair + coerce) โ
โ Strict mode checker โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Repair JSON repair (8 rules) โ
โ Type coercion (int/float/bool) โ
โ Prompt injection filter โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ DeepSeek API DeepSeekClient โ
โ Thinking / FIM / Batch / Balance โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Features
DeepSeek Thinking Mode โ Fully Leveraged
Thinking stays enabled throughout the conversation for deep reasoning. budget_tokens=2048 caps per-step cost. Reasoning content is compressed for efficient passback. Stable mode achieves top quality (8.8) across all scenarios.
agent = DeepSeekAgent(thinking=True, mode="stable") # thinking throughout + budget control
JSON Repair Pipeline
8 rules with a state machine that tracks both single- and double-quote contexts. LIFO stack for brace closure. Function-call syntax converter. Handles every known DeepSeek malformed-JSON pattern.
| Rule | Example Input | Repaired |
|---|---|---|
| Markdown fences | ```json\n{...}\n``` |
{...} |
| Function-call syntax | fn(city="Beijing") |
{"city":"Beijing"} |
| Single quotes | {'key':'val'} |
{"key":"val"} |
| Missing braces | {"a":[1,{"b":2 |
{"a":[1,{"b":2}]} |
Prompt Cache Stabilization
DeepSeek caches from byte 0. SeekFlow freezes the system prompt prefix and uses append-only compression to maintain 90%+ cache hit rates across multi-turn conversations.
from seekflow import CacheStabilizer
stabilizer = CacheStabilizer()
stabilizer.freeze(system_prompt, tool_schemas=tools)
# Every API call: stabilizer.ensure_stable_prefix(messages)
R1 Thought Harvesting
Extracts structured decision points (subgoals, hypotheses, uncertainties) from reasoning content. Injects them as compact insights rather than passing back full verbose reasoning chains.
from seekflow import harvest_thoughts
ht = harvest_thoughts(reasoning_content)
# โ subgoals: ["calculate ROI for all 3 companies"]
# โ hypotheses: ["A has lowest debt ratio"]
# โ uncertainties: ["C's volatility impact unclear"]
Production Reliability
| Component | Description |
|---|---|
| Circuit Breaker | 3-state (CLOSEDโOPENโHALF_OPEN). Prevents cascading failures |
| Retry Executor | Exponential backoff + jitter. Rate-limit aware (429 handling) |
| Tool Cache | LRU+TTL. SHA256 keys with argument-order independence |
| Context Window | Auto-trim preserves tool-call/result pairs. Append-only compression |
| Trace Recorder | Full execution timeline. JSON export for debugging |
| Cost Tracker | Cache-aware pricing. Real-time cost per agent run |
DeepSeek-Native Features
| Feature | Description |
|---|---|
| Thinking auto-management | Single-turn=on, multi-turn=auto-disable with warning |
| FIM completions | fim_complete() for code infilling (beta endpoint) |
| Batch API | 50% cost savings for bulk processing |
| Balance check | Pre-flight balance query with 5-min cache |
| Rate limit awareness | X-RateLimit-Remaining/Reset header parsing |
| Chinese token counting | CJK-aware fallback (1.5 tokens/char, not 0.25) |
Run Demos
4 production scenarios with blind judge comparison against LangChain and CrewAI:
export DEEPSEEK_API_KEY="sk-..."
python examples/demo_financial.py # Financial portfolio analysis
python examples/demo_supply_chain.py # Supply chain risk assessment
python examples/demo_code_auditor.py # Code review & security audit
python examples/demo_research.py # Multi-topic research synthesis
Multi-round benchmark with statistical analysis:
python examples/multi_round_benchmark.py --rounds 3
Comparison
| Feature | SeekFlow | LangChain | CrewAI |
|---|---|---|---|
| Thinking mode | Auto-hybrid | Manual config | Not supported |
| JSON repair | 8-rule pipeline | None | None |
| Cache stabilization | CacheStabilizer | None | None |
| Circuit breaker | 3-state | None | None |
| FIM | Built-in | None | None |
| Balance check | Built-in | None | None |
| R1 thought harvesting | Built-in | None | None |
| Self-consistency branching | Built-in | None | None |
| DeepSeek-optimized presets | 7 agents | Generic only | Generic only |
| Prompt injection filter | Built-in | None | None |
| MCP support | Built-in + fallback | Community | None |
| Dependencies | 6 | 40+ | 30+ |
Documentation
- Examples โ 4 demo scenarios + multi-round benchmark
- Architecture Notes โ performance optimization guide
- Tests โ 418 tests covering all modules
- Presets โ 7 DeepSeek-optimized agent templates
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file seekflow-0.1.0.tar.gz.
File metadata
- Download URL: seekflow-0.1.0.tar.gz
- Upload date:
- Size: 186.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9793aadb7491f8bdd115114b20927870d5fba662ed3378b7528cb47d192e1cc5
|
|
| MD5 |
9ca159198bc0fcf57195efe651fdf0e7
|
|
| BLAKE2b-256 |
6f57a61ada9c955a1d04222796d25ccb84bd0cf7d9ba457644ad9c274e39659a
|
File details
Details for the file seekflow-0.1.0-py3-none-any.whl.
File metadata
- Download URL: seekflow-0.1.0-py3-none-any.whl
- Upload date:
- Size: 122.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d4797ada7a179448a0f5efd0785d49f13d097a10cd1b8cfb62af69dff987b96
|
|
| MD5 |
d770788edc092dbf78575e2019ef5563
|
|
| BLAKE2b-256 |
5768fad1e5b36a6ccf25aac44d4ac79871decd9cf32f618d47c9a02264ad3440
|