Collapse RunWithOpts duplicates into variadic options
Run, RunStreamed, and Resume each shipped both a no-options form and a mirror *WithOpts form taking variadic RunOption. Variadic parameters are backward-compatible additions, so the wrappers were dead surface. Make Run, RunStreamed, and Resume directly variadic and update the two internal callers. Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
@@ -480,7 +480,7 @@ func TestRestore(t *testing.T) {
|
|||||||
close(stopCh)
|
close(stopCh)
|
||||||
ctx := agent.WithStopSignal(context.Background(), stopCh)
|
ctx := agent.WithStopSignal(context.Background(), stopCh)
|
||||||
|
|
||||||
_, err := ag.RunWithOpts(
|
_, err := ag.Run(
|
||||||
ctx,
|
ctx,
|
||||||
[]llm.Message{
|
[]llm.Message{
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -115,11 +115,7 @@ func blockingCallLLM(ctx context.Context, agent *Agent, req *llm.ChatCompletionR
|
|||||||
return acc.Response(), nil
|
return acc.Response(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Agent) Run(ctx context.Context, messages []llm.Message) (*Result, error) {
|
func (a *Agent) Run(ctx context.Context, messages []llm.Message, opts ...RunOption) (*Result, error) {
|
||||||
return a.RunWithOpts(ctx, messages)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *Agent) RunWithOpts(ctx context.Context, messages []llm.Message, opts ...RunOption) (*Result, error) {
|
|
||||||
ro := runOpts{
|
ro := runOpts{
|
||||||
callLLM: blockingCallLLM,
|
callLLM: blockingCallLLM,
|
||||||
onEvent: noopEvent,
|
onEvent: noopEvent,
|
||||||
@@ -1244,11 +1240,7 @@ func runOutputGuardrails(ctx context.Context, agent *Agent, message llm.Message)
|
|||||||
// the provided ResumeInput, then re-enters the agent loop. Input guardrails
|
// the provided ResumeInput, then re-enters the agent loop. Input guardrails
|
||||||
// are not re-evaluated because the messages were already validated in the
|
// are not re-evaluated because the messages were already validated in the
|
||||||
// original Run call.
|
// original Run call.
|
||||||
func Resume(ctx context.Context, interrupted *InterruptedError, input ResumeInput) (*Result, error) {
|
func Resume(ctx context.Context, interrupted *InterruptedError, input ResumeInput, opts ...RunOption) (*Result, error) {
|
||||||
return ResumeWithOpts(ctx, interrupted, input)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ResumeWithOpts(ctx context.Context, interrupted *InterruptedError, input ResumeInput, opts ...RunOption) (*Result, error) {
|
|
||||||
ro := runOpts{
|
ro := runOpts{
|
||||||
callLLM: blockingCallLLM,
|
callLLM: blockingCallLLM,
|
||||||
onEvent: noopEvent,
|
onEvent: noopEvent,
|
||||||
|
|||||||
@@ -59,11 +59,7 @@ func (sr *StreamedRun) Wait() (*Result, error) {
|
|||||||
return sr.result, sr.err
|
return sr.result, sr.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Agent) RunStreamed(ctx context.Context, messages []llm.Message) *StreamedRun {
|
func (a *Agent) RunStreamed(ctx context.Context, messages []llm.Message, opts ...RunOption) *StreamedRun {
|
||||||
return a.RunStreamedWithOpts(ctx, messages)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *Agent) RunStreamedWithOpts(ctx context.Context, messages []llm.Message, opts ...RunOption) *StreamedRun {
|
|
||||||
events := make(chan StreamEvent, 64)
|
events := make(chan StreamEvent, 64)
|
||||||
sr := &StreamedRun{
|
sr := &StreamedRun{
|
||||||
Events: events,
|
Events: events,
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ func (h *agentRunHandler) executeRun(ctx context.Context, run *coredata.AgentRun
|
|||||||
if err := json.Unmarshal(run.InputMessages, &inputMsgs); err != nil {
|
if err := json.Unmarshal(run.InputMessages, &inputMsgs); err != nil {
|
||||||
runErr = fmt.Errorf("cannot unmarshal input messages: %w", err)
|
runErr = fmt.Errorf("cannot unmarshal input messages: %w", err)
|
||||||
} else {
|
} else {
|
||||||
result, runErr = a.RunWithOpts(
|
result, runErr = a.Run(
|
||||||
ctx,
|
ctx,
|
||||||
inputMsgs,
|
inputMsgs,
|
||||||
agent.WithCheckpointer(h.store, runID),
|
agent.WithCheckpointer(h.store, runID),
|
||||||
|
|||||||
Reference in New Issue
Block a user