diff --git a/pkg/api/handlers/agent.go b/pkg/api/handlers/agent.go index 4060397f..72f2af7f 100644 --- a/pkg/api/handlers/agent.go +++ b/pkg/api/handlers/agent.go @@ -223,7 +223,7 @@ func (a *AgentHandler) UploadKnowledge(ctx context.Context, req api.Request) err return err } - agent.Status.IngestKnowledge = true + agent.Status.KnowledgeGeneration++ agent.Status.HasKnowledge = true return req.Storage.Status().Update(ctx, &agent) } @@ -248,7 +248,7 @@ func (a *AgentHandler) DeleteKnowledge(ctx context.Context, req api.Request) err return fmt.Errorf("failed to list files in workspace %s: %w", agent.Status.KnowledgeWorkspaceID, err) } - agent.Status.IngestKnowledge = true + agent.Status.KnowledgeGeneration++ agent.Status.HasKnowledge = len(files) > 0 return req.Storage.Status().Update(ctx, &agent) } @@ -273,6 +273,6 @@ func (a *AgentHandler) IngestKnowledge(ctx context.Context, req api.Request) err return nil } - agent.Status.IngestKnowledge = true + agent.Status.KnowledgeGeneration++ return req.Storage.Status().Update(ctx, &agent) } diff --git a/pkg/api/handlers/threads.go b/pkg/api/handlers/threads.go index c647078c..4fa2f843 100644 --- a/pkg/api/handlers/threads.go +++ b/pkg/api/handlers/threads.go @@ -110,7 +110,7 @@ func (a *ThreadHandler) UploadKnowledge(ctx context.Context, req api.Request) er return err } - thread.Status.IngestKnowledge = true + thread.Status.KnowledgeGeneration++ thread.Status.HasKnowledge = true return req.Storage.Status().Update(ctx, &thread) } @@ -135,7 +135,7 @@ func (a *ThreadHandler) DeleteKnowledge(ctx context.Context, req api.Request) er return fmt.Errorf("failed to list files in workspace %s: %w", thread.Spec.KnowledgeWorkspaceID, err) } - thread.Status.IngestKnowledge = true + thread.Status.KnowledgeGeneration++ thread.Status.HasKnowledge = len(files) > 0 return req.Storage.Status().Update(ctx, &thread) } @@ -160,6 +160,6 @@ func (a *ThreadHandler) IngestKnowledge(ctx context.Context, req api.Request) er return nil } - thread.Status.IngestKnowledge = true + thread.Status.KnowledgeGeneration++ return req.Storage.Status().Update(ctx, &thread) } diff --git a/pkg/controller/handlers/agents/agents.go b/pkg/controller/handlers/agents/agents.go index 02728be4..47ac845d 100644 --- a/pkg/controller/handlers/agents/agents.go +++ b/pkg/controller/handlers/agents/agents.go @@ -54,7 +54,7 @@ func (a *AgentHandler) RemoveWorkspaces(req router.Request, resp router.Response func (a *AgentHandler) IngestKnowledge(req router.Request, resp router.Response) error { agent := req.Object.(*v1.Agent) - if !agent.Status.IngestKnowledge || !agent.Status.HasKnowledge { + if agent.Status.KnowledgeGeneration == agent.Status.ObservedKnowledgeGeneration || !agent.Status.HasKnowledge { return nil } @@ -62,6 +62,6 @@ func (a *AgentHandler) IngestKnowledge(req router.Request, resp router.Response) return err } - agent.Status.IngestKnowledge = false + agent.Status.ObservedKnowledgeGeneration = agent.Status.KnowledgeGeneration return nil } diff --git a/pkg/controller/handlers/threads/threads.go b/pkg/controller/handlers/threads/threads.go index 69c7cfae..bb0b3eac 100644 --- a/pkg/controller/handlers/threads/threads.go +++ b/pkg/controller/handlers/threads/threads.go @@ -58,7 +58,7 @@ func (t *ThreadHandler) RemoveWorkspaces(req router.Request, resp router.Respons func (t *ThreadHandler) IngestKnowledge(req router.Request, resp router.Response) error { thread := req.Object.(*v1.Thread) - if !thread.Status.IngestKnowledge || !thread.Status.HasKnowledge { + if thread.Status.KnowledgeGeneration == thread.Status.ObservedKnowledgeGeneration || !thread.Status.HasKnowledge { return nil } @@ -66,6 +66,6 @@ func (t *ThreadHandler) IngestKnowledge(req router.Request, resp router.Response return err } - thread.Status.IngestKnowledge = false + thread.Status.ObservedKnowledgeGeneration = thread.Status.KnowledgeGeneration return nil } diff --git a/pkg/storage/apis/otto.gptscript.ai/v1/agent.go b/pkg/storage/apis/otto.gptscript.ai/v1/agent.go index 867da18a..126e89f7 100644 --- a/pkg/storage/apis/otto.gptscript.ai/v1/agent.go +++ b/pkg/storage/apis/otto.gptscript.ai/v1/agent.go @@ -34,11 +34,12 @@ type AgentSpec struct { } type AgentStatus struct { - Conditions []metav1.Condition `json:"conditions,omitempty"` - HasKnowledge bool `json:"hasKnowledge,omitempty"` - IngestKnowledge bool `json:"ingestKnowledge,omitempty"` - WorkspaceID string `json:"workspaceID,omitempty"` - KnowledgeWorkspaceID string `json:"knowledgeWorkspaceID,omitempty"` + Conditions []metav1.Condition `json:"conditions,omitempty"` + HasKnowledge bool `json:"hasKnowledge,omitempty"` + KnowledgeGeneration int64 `json:"knowledgeGeneration,omitempty"` + ObservedKnowledgeGeneration int64 `json:"observedKnowledgeGeneration,omitempty"` + WorkspaceID string `json:"workspaceID,omitempty"` + KnowledgeWorkspaceID string `json:"knowledgeWorkspaceID,omitempty"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/pkg/storage/apis/otto.gptscript.ai/v1/thread.go b/pkg/storage/apis/otto.gptscript.ai/v1/thread.go index a4256cf5..8359200d 100644 --- a/pkg/storage/apis/otto.gptscript.ai/v1/thread.go +++ b/pkg/storage/apis/otto.gptscript.ai/v1/thread.go @@ -33,14 +33,15 @@ type ThreadSpec struct { } type ThreadStatus struct { - Description string `json:"description,omitempty"` - LastRunName string `json:"lastRunName,omitempty"` - LastRunState gptscriptclient.RunState `json:"lastRunState,omitempty"` - LastRunOutput string `json:"lastRunOutput,omitempty"` - LastRunError string `json:"lastRunError,omitempty"` - Conditions []metav1.Condition `json:"conditions,omitempty"` - HasKnowledge bool `json:"hasKnowledge,omitempty"` - IngestKnowledge bool `json:"ingestKnowledge,omitempty"` + Description string `json:"description,omitempty"` + LastRunName string `json:"lastRunName,omitempty"` + LastRunState gptscriptclient.RunState `json:"lastRunState,omitempty"` + LastRunOutput string `json:"lastRunOutput,omitempty"` + LastRunError string `json:"lastRunError,omitempty"` + Conditions []metav1.Condition `json:"conditions,omitempty"` + HasKnowledge bool `json:"hasKnowledge,omitempty"` + KnowledgeGeneration int64 `json:"knowledgeGeneration,omitempty"` + ObservedKnowledgeGeneration int64 `json:"observedKnowledgeGeneration,omitempty"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/pkg/storage/openapi/generated/openapi_generated.go b/pkg/storage/openapi/generated/openapi_generated.go index 2f132025..2dc42f0a 100644 --- a/pkg/storage/openapi/generated/openapi_generated.go +++ b/pkg/storage/openapi/generated/openapi_generated.go @@ -369,10 +369,16 @@ func schema_storage_apis_ottogptscriptai_v1_AgentStatus(ref common.ReferenceCall Format: "", }, }, - "ingestKnowledge": { + "knowledgeGeneration": { SchemaProps: spec.SchemaProps{ - Type: []string{"boolean"}, - Format: "", + Type: []string{"integer"}, + Format: "int64", + }, + }, + "observedKnowledgeGeneration": { + SchemaProps: spec.SchemaProps{ + Type: []string{"integer"}, + Format: "int64", }, }, "workspaceID": { @@ -1178,10 +1184,16 @@ func schema_storage_apis_ottogptscriptai_v1_ThreadStatus(ref common.ReferenceCal Format: "", }, }, - "ingestKnowledge": { + "knowledgeGeneration": { SchemaProps: spec.SchemaProps{ - Type: []string{"boolean"}, - Format: "", + Type: []string{"integer"}, + Format: "int64", + }, + }, + "observedKnowledgeGeneration": { + SchemaProps: spec.SchemaProps{ + Type: []string{"integer"}, + Format: "int64", }, }, },