MCPcopy Create free account
hub / github.com/ForestHubAI/edge-agents / parseChoiceToken

Function parseChoiceToken

go/engine/node/agent.go:245–256  ·  view source on GitHub ↗

parseChoiceToken extracts the branch index from a choice_N token and verifies it is within range.

(token string, branchCount int)

Source from the content-addressed store, hash-verified

243// verifies it is within range.
244func parseChoiceToken(token string, branchCount int) (int, error) {
245 const prefix = "choice_"
246 rest, ok := strings.CutPrefix(token, prefix)
247 if !ok {
248 return 0, fmt.Errorf("invalid choice token %q", token)
249 }
250 idx, err := strconv.Atoi(rest)
251 if err != nil || idx < 0 || idx >= branchCount {
252 return 0, fmt.Errorf("invalid choice token %q", token)
253 }
254 return idx, nil
255}
256
257// Tools exposes this Agent as an LLM-callable tool. Following the llmproxy
258// agent.AsTool convention, the tool accepts a single "prompt" string and
259// returns the agent's final answer.

Callers 2

TestParseChoiceTokenFunction · 0.85
nextMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestParseChoiceTokenFunction · 0.68