Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

agent: route inference through a test seam so hook dispatch is testable without a graph

Adeshina Lasisi4066f6efaeaa
diff --git a/laya-go/agent/agent.go b/laya-go/agent/agent.go
index 29010811..c2e8ec48 100644
--- a/laya-go/agent/agent.go
+++ b/laya-go/agent/agent.go
@@ -269,7 +269,7 @@ func (a *Agent) PredictBatch(ctx context.Context, states []any, qs schema.Questi
if hooks := a.composeHooks(c); len(hooks) > 0 {
return a.predictHooked(ctx, states, qs, c, g, hooks)
}
- preds, err := a.predictStates(ctx, states, qs, c)
+ preds, err := a.inferStates(ctx, states, qs, c)
if err != nil {
return nil, err
}
diff --git a/laya-go/agent/hooks.go b/laya-go/agent/hooks.go
index 76d1d36e..31d29dc5 100644
--- a/laya-go/agent/hooks.go
+++ b/laya-go/agent/hooks.go
@@ -279,6 +279,9 @@ type hookState struct {
sem chan struct{} // the serial lock, a channel so a waiter can give up
done chan struct{} // closed by Close
closeOnce sync.Once
+
+ // stub replaces inference in tests; nil in production.
+ stub func(ctx context.Context, states []any, qs schema.Questions, c call) ([]schema.Prediction, error)
}
func newHookState(o options) *hookState {
@@ -473,12 +476,20 @@ func newRunID() string {
// predictHooked is PredictBatch with hooks, as ONNXAgent.predict_batch: start, inference unless a
// hook answered, then on any failure OnError, and always OnPredictEnd.
+// inferStates is predictStates, or the test stub standing in for it.
+func (a *Agent) inferStates(ctx context.Context, states []any, qs schema.Questions, c call) ([]schema.Prediction, error) {
+ if a.hk != nil && a.hk.stub != nil {
+ return a.hk.stub(ctx, states, qs, c)
+ }
+ return a.predictStates(ctx, states, qs, c)
+}
+
func (a *Agent) predictHooked(ctx context.Context, states []any, qs schema.Questions, c call, g *gate, hooks []Hook) ([]schema.Prediction, error) {
pc := &PredictContext{States: states, Questions: qs, RunID: newRunID(), Model: schema.Model, Agent: a, StartedAt: time.Now()}
err := a.dispatch(ctx, evStart, hooks, pc)
if err == nil && pc.Results == nil {
c.maxLen, c.headMaxLen = pc.MaxLen, pc.HeadMaxLen
- pc.Results, err = a.predictStates(ctx, pc.States, pc.Questions, c)
+ pc.Results, err = a.inferStates(ctx, pc.States, pc.Questions, c)
}
if err != nil {
pc.Err = err