yao/agent/assistant/agent.go
Max 27d4cd9555 Refactor context and assistant methods for improved stack management and resource cleanup
- Updated Stream and Run methods in the Assistant to use pointer receivers for context, enhancing performance and clarity.
- Introduced stack management in context handling, including initialization and cleanup of stack references.
- Enhanced the Release method in Context to ensure proper cleanup of resources, including stacks and writer references.
- Added new stack status constants and validation to improve traceability and error handling in agent operations.
- Removed the obsolete JavaScript API file to streamline the codebase.
2025-11-12 11:24:25 +08:00

33 lines
895 B
Go

package assistant
import "github.com/yaoapp/yao/agent/context"
// Stream stream the agent
func (ast *Assistant) Stream(ctx *context.Context, messages []context.Message, handler context.StreamFunc) error {
// Initialize stack and auto-handle completion/failure/restore
_, traceID, done := context.EnterStack(ctx, ast.ID, ctx.Referer)
defer done()
_ = traceID // traceID is available for trace logging
// Request Create hook ( Optional )
// LLM Call Stream ( Optional )
// Request Done hook ( Optional )
return nil
}
// Run run the agent
func (ast *Assistant) Run(ctx *context.Context, messages []context.Message) (*context.Response, error) {
// Initialize stack and auto-handle completion/failure/restore
_, traceID, done := context.EnterStack(ctx, ast.ID, ctx.Referer)
defer done()
_ = traceID // traceID is available for trace logging
return &context.Response{}, nil
}