MCPcopy Create free account
hub / github.com/astercloud/aster / BenchmarkPhase4Stack

Function BenchmarkPhase4Stack

pkg/middleware/phase4_bench_test.go:176–220  ·  view source on GitHub ↗

BenchmarkPhase4Stack 基准测试: Phase 4 完整中间件栈

(b *testing.B)

Source from the content-addressed store, hash-verified

174
175// BenchmarkPhase4Stack 基准测试: Phase 4 完整中间件栈
176func BenchmarkPhase4Stack(b *testing.B) {
177 ctx := context.Background()
178
179 // 创建后端
180 backend := newMockBackend()
181 backend.files["/agent.md"] = "You are a helpful assistant"
182
183 // 创建中间件
184 memoryMW, _ := NewAgentMemoryMiddleware(&AgentMemoryMiddlewareConfig{
185 Backend: backend,
186 MemoryPath: "/memories/",
187 })
188
189 summarizationMW, _ := NewSummarizationMiddleware(&SummarizationMiddlewareConfig{
190 Summarizer: mockSummarizer("Summary", false),
191 MaxTokensBeforeSummary: 100000, // 不触发总结
192 MessagesToKeep: 3,
193 })
194
195 req := &ModelRequest{
196 SystemPrompt: "Test prompt",
197 Messages: []types.Message{
198 {Role: types.MessageRoleUser, ContentBlocks: []types.ContentBlock{&types.TextBlock{Text: "Hello"}}},
199 },
200 }
201
202 // 构建中间件链
203 handler := func(ctx context.Context, req *ModelRequest) (*ModelResponse, error) {
204 return &ModelResponse{
205 Message: types.Message{
206 Role: types.MessageRoleAssistant,
207 ContentBlocks: []types.ContentBlock{&types.TextBlock{Text: "Response"}},
208 },
209 }, nil
210 }
211
212 // Memory -> Summarization -> Handler
213 summarizationHandler := func(ctx context.Context, req *ModelRequest) (*ModelResponse, error) {
214 return summarizationMW.WrapModelCall(ctx, req, handler)
215 }
216
217 for b.Loop() {
218 _, _ = memoryMW.WrapModelCall(ctx, req, summarizationHandler)
219 }
220}
221
222// BenchmarkExtractMessageContent 基准测试: 消息内容提取
223func BenchmarkExtractMessageContent(b *testing.B) {

Callers

nothing calls this directly

Calls 6

WrapModelCallMethod · 0.95
WrapModelCallMethod · 0.95
newMockBackendFunction · 0.85
NewAgentMemoryMiddlewareFunction · 0.85
mockSummarizerFunction · 0.85

Tested by

no test coverage detected