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

Method Reason

pkg/reasoning/engine.go:51–85  ·  view source on GitHub ↗

Reason 执行推理

(ctx context.Context, query string, systemPrompt string)

Source from the content-addressed store, hash-verified

49
50// Reason 执行推理
51func (e *Engine) Reason(ctx context.Context, query string, systemPrompt string) (*Chain, error) {
52 chain := NewChain(ChainConfig{
53 MinSteps: e.config.MinSteps,
54 MaxSteps: e.config.MaxSteps,
55 MinConfidence: e.config.MinConfidence,
56 })
57
58 // 构建推理提示词
59 reasoningPrompt := e.buildReasoningPrompt(query, systemPrompt)
60
61 // 执行推理循环
62 for chain.ShouldContinue() {
63 step, err := e.executeReasoningStep(ctx, chain, reasoningPrompt)
64 if err != nil {
65 return chain, fmt.Errorf("execute reasoning step: %w", err)
66 }
67
68 if err := chain.AddStep(*step); err != nil {
69 return chain, fmt.Errorf("add reasoning step: %w", err)
70 }
71
72 // 如果步骤指示完成,则退出
73 if step.NextAction == NextActionComplete {
74 break
75 }
76
77 // 如果置信度过低且已达到最小步数,则退出
78 if step.Confidence < e.config.MinConfidence && len(chain.Steps) >= e.config.MinSteps {
79 break
80 }
81 }
82
83 chain.Complete()
84 return chain, nil
85}
86
87// executeReasoningStep 执行单个推理步骤
88func (e *Engine) executeReasoningStep(ctx context.Context, chain *Chain, basePrompt string) (*Step, error) {

Callers

nothing calls this directly

Calls 6

buildReasoningPromptMethod · 0.95
ShouldContinueMethod · 0.95
executeReasoningStepMethod · 0.95
AddStepMethod · 0.95
CompleteMethod · 0.95
NewChainFunction · 0.85

Tested by

no test coverage detected