Skip to content

feat(agent): market query APIs, cache middleware, and run stability - #142

Merged
363045841 merged 9 commits into
feat/agentfrom
feat/agent-market-query-api
Sep 2, 2026
Merged

feat(agent): market query APIs, cache middleware, and run stability#142
363045841 merged 9 commits into
feat/agentfrom
feat/agent-market-query-api

Conversation

@363045841

Copy link
Copy Markdown
Owner

概述

将 Agent 的行情查询能力、缓存抽象与推理运行稳定性改进合并到 feat/agent。本 PR 覆盖分支上全部 9 个提交。

改动内容

行情数据:缓存中间件化(data

  • 将原有 Buffer 重构为缓存中间件,统一 marketDataCache / timeShareBuffer / timeShareRangeBuffer 的查询路径。
  • 新增实例级缓存内存上限与 LRU 淘汰,并暴露缓存统计与清理动作。
  • 移除 fetchSchedulerdataBuffer.effects.ts,查询/重试逻辑收敛进缓存层。

Agent 无状态查询 API(agent

  • 新增 market_bars_query / market_timeshare_query / market_timeshare_range_query / instruments_query_name / indicators_query 只读工具。
  • marketDataTextFormatter 统一行情文本输出,携带运行时数据源信息。
  • market_bars_querybefore 游标接受 YYYY-MM-DD UTC 日期,在包装层转为毫秒时间戳,领域层保持毫秒契约以支持分页。

Agent 运行稳定性(agent-runtime

  • 运行超时由绝对 deadline 改为“无活动超时”:流式输出与工具进度会续期,真正静默才中断。
  • 推理模型输出预算由 4096 提至 16384,并采用 low 推理强度,避免长链思考耗尽共享预算导致正文被截断。

UI(vue

  • 工具调用卡片改为可折叠(<details>/<summary>),避免长输入/结果占据整条时间线。

验证

  • packages/agent-runtime 单测 58 项通过,tsc 构建通过。
  • packages/core 单测通过,tsc 构建通过。

Expose queryBars / queryTimeShare / queryTimeShareRange on ChartAgentController,
each directly registered as a @tool, so UI and Agent share one public API for
any-symbol market data without depending on the active chart selection, viewport,
or renderer.

Route queries through the same Provider registry via SourceRouter and return
serializable domain snapshots with the resolved source. Thread the tool AbortSignal
through SourceRouter probe, instrument resolution, and Provider fetches.

The Buffer still owns the chart load path; its fetch responsibilities move onto
these APIs in a later step.
…et-data queries

Replace DataBuffer's own fetch orchestration with a chart-scoped MarketDataCache that owns pagination, retries, in-flight dedupe, auto-source locking and lifecycle cleanup. DataBuffer and TimeShareBuffer become snapshot adapters publishing data/loading/error only. Chart initial load, incremental history pages, comparison and time-share loads all route through the shared cache, and the same cache backs the Agent @tool queries, removing the second fetch path. Bars queries expose limit/before cursor semantics directly, so pagination is driven by callers instead of range extrapolation. Vue chart chip no longer reports success as an error when data loading settles without an explicit error.

BREAKING CHANGE: KLineBuffer and TimeShareBuffer drop setRequestFetch/setRangeRequestFetch/ensureRange; provider requests are owned by MarketDataCache. Bars cache queries use limit/before instead of latest/range. Deletes FetchScheduler, dataBuffer.effects contract and legacy page request/result types. Closes #140
…ettings UI

Give MarketDataCache a per-chart-instance soft memory cap (default 50 MiB) so long sessions that switch many symbols no longer grow the cache unbounded. Every cache write and hit updates an LRU order; when the cap is exceeded the least-recently-used complete bars, time-share or multi-day time-share entry is evicted, while a single entry that itself exceeds the cap is kept so the triggering query still returns. Size is an approximation of the serializable payload with JS overhead, not the real browser heap. Expose the cap and current approximate usage through a marketDataCacheStats controller signal and a new cache section in the settings dialog (5-512 MiB), applying eviction immediately on change. UI reads tolerate a missing stats signal so older controller mocks keep working.
…a sources

Add a chart-scoped clearMarketDataCache controller method wired through the settings dialog, expose the cache limit as fixed MiB dropdown options (50-500), and reorganize the dialog: cache limit, usage, clear action and the aggregation-source entry now live under a single data-source section whose groups all collapse by default. Move the cache limit setting off the experimental group so it is no longer rendered twice.
…rces

Convert market query tool results to compact Markdown tables with readable timezone times so the model spends fewer tokens on structure. Inject the current Asia/Shanghai date and time into the system prompt as a reference, expose the exact enabled sourceIds in tool descriptions, and reject unavailable sourceIds and out-of-range limits with messages that let the model correct its next call.
The market_bars_query tool now takes before as an exclusive YYYY-MM-DD UTC
date instead of a raw millisecond timestamp, and converts it to UTC ms
before delegating to the underlying stateless queryBars API. The domain
layer keeps the millisecond cursor contract for pagination.
The run timeout was an absolute deadline from the start of the run, so a
slowly streaming model or long-running tool progress was interrupted mid
output even though it was making progress. Recompute the deadline on every
Pi event so it becomes an idle timeout, and lower the default idle window
to 30s.
Responses providers count reasoning and visible text against one output budget. Raise the budget and use low reasoning effort so long tool-driven analyses can reach a visible conclusion instead of ending during hidden reasoning.
Keep tool-call details available without forcing long inputs and results to occupy the entire Agent timeline.
@363045841
363045841 merged commit 857ef4d into feat/agent Sep 2, 2026
8 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in KLineChartQuant Requests Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant