Skip to content

Commit

Permalink
Merge pull request #9 from thedadams/knowledge-generation
Browse files Browse the repository at this point in the history
fix: use knowledge generation instead of boolean
  • Loading branch information
thedadams authored Sep 11, 2024
2 parents fd3b303 + 3896b75 commit 280442e
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 29 deletions.
6 changes: 3 additions & 3 deletions pkg/api/handlers/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
6 changes: 3 additions & 3 deletions pkg/api/handlers/threads.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions pkg/controller/handlers/agents/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ 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
}

if err := a.Ingester.IngestKnowledge(req.Ctx, agent.Namespace, agent.Status.KnowledgeWorkspaceID); err != nil {
return err
}

agent.Status.IngestKnowledge = false
agent.Status.ObservedKnowledgeGeneration = agent.Status.KnowledgeGeneration
return nil
}
4 changes: 2 additions & 2 deletions pkg/controller/handlers/threads/threads.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ 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
}

if err := t.Ingester.IngestKnowledge(req.Ctx, thread.Namespace, thread.Spec.KnowledgeWorkspaceID); err != nil {
return err
}

thread.Status.IngestKnowledge = false
thread.Status.ObservedKnowledgeGeneration = thread.Status.KnowledgeGeneration
return nil
}
11 changes: 6 additions & 5 deletions pkg/storage/apis/otto.gptscript.ai/v1/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions pkg/storage/apis/otto.gptscript.ai/v1/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 18 additions & 6 deletions pkg/storage/openapi/generated/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 280442e

Please sign in to comment.