Skip to main content

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

Python License Tests DeepSeek

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

seekflow-0.1.0.tar.gz (186.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

seekflow-0.1.0-py3-none-any.whl (122.1 kB view details)

Uploaded Python 3

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

Hashes for seekflow-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9793aadb7491f8bdd115114b20927870d5fba662ed3378b7528cb47d192e1cc5
MD5 9ca159198bc0fcf57195efe651fdf0e7
BLAKE2b-256 6f57a61ada9c955a1d04222796d25ccb84bd0cf7d9ba457644ad9c274e39659a

See more details on using hashes here.

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

Hashes for seekflow-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d4797ada7a179448a0f5efd0785d49f13d097a10cd1b8cfb62af69dff987b96
MD5 d770788edc092dbf78575e2019ef5563
BLAKE2b-256 5768fad1e5b36a6ccf25aac44d4ac79871decd9cf32f618d47c9a02264ad3440

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page