Add weighted random workflow steps and a random choice agent tool
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"g.fc.run/ai/byre/internal/api"
|
||||
"g.fc.run/ai/byre/internal/workflow"
|
||||
)
|
||||
|
||||
type FrozenWorkflow struct {
|
||||
@@ -38,7 +39,7 @@ func (s *Store) ListWorkflows(ctx context.Context) ([]api.WorkflowSummary, error
|
||||
}
|
||||
|
||||
func (s *Store) GetWorkflow(ctx context.Context, name string) (api.WorkflowDefinition, error) {
|
||||
f, err := s.FreezeWorkflow(ctx, name)
|
||||
f, err := s.savedWorkflow(ctx, name)
|
||||
return f.Definition, err
|
||||
}
|
||||
|
||||
@@ -192,6 +193,20 @@ func (s *Store) DeleteWorkflow(ctx context.Context, name, actor string) error {
|
||||
}
|
||||
|
||||
func (s *Store) FreezeWorkflow(ctx context.Context, name string) (FrozenWorkflow, error) {
|
||||
f, err := s.savedWorkflow(ctx, name)
|
||||
if err != nil || !workflow.HasRandom(f.Definition) {
|
||||
return f, err
|
||||
}
|
||||
f.Definition = workflow.Resolve(f.Definition)
|
||||
err = s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
|
||||
id, err := insertDefinition(ctx, tx, f.Definition)
|
||||
f.DefinitionID = id
|
||||
return err
|
||||
})
|
||||
return f, err
|
||||
}
|
||||
|
||||
func (s *Store) savedWorkflow(ctx context.Context, name string) (FrozenWorkflow, error) {
|
||||
f := FrozenWorkflow{Name: name}
|
||||
err := s.db.QueryRowContext(ctx, `SELECT definition_id FROM workflows WHERE name = ?`, name).Scan(&f.DefinitionID)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
|
||||
Reference in New Issue
Block a user