add start/pause (to improve further)
This commit is contained in:
@@ -32,6 +32,7 @@ type Agent struct {
|
|||||||
nextAction Action
|
nextAction Action
|
||||||
currentConversation Messages
|
currentConversation Messages
|
||||||
selfEvaluationInProgress bool
|
selfEvaluationInProgress bool
|
||||||
|
pause bool
|
||||||
|
|
||||||
newConversations chan openai.ChatCompletionMessage
|
newConversations chan openai.ChatCompletionMessage
|
||||||
}
|
}
|
||||||
@@ -137,6 +138,24 @@ func (a *Agent) Stop() {
|
|||||||
a.context.Cancel()
|
a.context.Cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Agent) Pause() {
|
||||||
|
a.Lock()
|
||||||
|
defer a.Unlock()
|
||||||
|
a.pause = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Agent) Resume() {
|
||||||
|
a.Lock()
|
||||||
|
defer a.Unlock()
|
||||||
|
a.pause = false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Agent) Paused() bool {
|
||||||
|
a.Lock()
|
||||||
|
defer a.Unlock()
|
||||||
|
return a.pause
|
||||||
|
}
|
||||||
|
|
||||||
func (a *Agent) runAction(chosenAction Action, decisionResult *decisionResult) (result string, err error) {
|
func (a *Agent) runAction(chosenAction Action, decisionResult *decisionResult) (result string, err error) {
|
||||||
for _, action := range a.systemInternalActions() {
|
for _, action := range a.systemInternalActions() {
|
||||||
if action.Definition().Name == chosenAction.Definition().Name {
|
if action.Definition().Name == chosenAction.Definition().Name {
|
||||||
@@ -174,6 +193,18 @@ func (a *Agent) runAction(chosenAction Action, decisionResult *decisionResult) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *Agent) consumeJob(job *Job, role string) {
|
func (a *Agent) consumeJob(job *Job, role string) {
|
||||||
|
a.Lock()
|
||||||
|
paused := a.pause
|
||||||
|
a.Unlock()
|
||||||
|
|
||||||
|
if paused {
|
||||||
|
if a.options.debugMode {
|
||||||
|
fmt.Println("Agent is paused, skipping job")
|
||||||
|
}
|
||||||
|
job.Result.Finish(fmt.Errorf("agent is paused"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// We are self evaluating if we consume the job as a system role
|
// We are self evaluating if we consume the job as a system role
|
||||||
selfEvaluation := role == SystemRole
|
selfEvaluation := role == SystemRole
|
||||||
|
|
||||||
|
|||||||
@@ -137,6 +137,27 @@ func (a *App) Delete(pool *AgentPool) func(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) Pause(pool *AgentPool) func(c *fiber.Ctx) error {
|
||||||
|
return func(c *fiber.Ctx) error {
|
||||||
|
fmt.Println("Pausing agent", c.Params("name"))
|
||||||
|
agent := pool.GetAgent(c.Params("name"))
|
||||||
|
if agent != nil {
|
||||||
|
agent.Pause()
|
||||||
|
}
|
||||||
|
return c.Redirect("/agents")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) Start(pool *AgentPool) func(c *fiber.Ctx) error {
|
||||||
|
return func(c *fiber.Ctx) error {
|
||||||
|
agent := pool.GetAgent(c.Params("name"))
|
||||||
|
if agent != nil {
|
||||||
|
agent.Resume()
|
||||||
|
}
|
||||||
|
return c.Redirect("/agents")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (a *App) Create(pool *AgentPool) func(c *fiber.Ctx) error {
|
func (a *App) Create(pool *AgentPool) func(c *fiber.Ctx) error {
|
||||||
return func(c *fiber.Ctx) error {
|
return func(c *fiber.Ctx) error {
|
||||||
config := AgentConfig{}
|
config := AgentConfig{}
|
||||||
|
|||||||
@@ -24,8 +24,13 @@ func RegisterRoutes(webapp *fiber.App, pool *AgentPool, db *InMemoryDatabase, ap
|
|||||||
})
|
})
|
||||||
|
|
||||||
webapp.Get("/agents", func(c *fiber.Ctx) error {
|
webapp.Get("/agents", func(c *fiber.Ctx) error {
|
||||||
|
statuses := map[string]bool{}
|
||||||
|
for _, a := range pool.List() {
|
||||||
|
statuses[a] = !pool.GetAgent(a).Paused()
|
||||||
|
}
|
||||||
return c.Render("views/agents", fiber.Map{
|
return c.Render("views/agents", fiber.Map{
|
||||||
"Agents": pool.List(),
|
"Agents": pool.List(),
|
||||||
|
"Status": statuses,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -72,6 +77,8 @@ func RegisterRoutes(webapp *fiber.App, pool *AgentPool, db *InMemoryDatabase, ap
|
|||||||
webapp.Post("/chat/:name", app.Chat(pool))
|
webapp.Post("/chat/:name", app.Chat(pool))
|
||||||
webapp.Post("/create", app.Create(pool))
|
webapp.Post("/create", app.Create(pool))
|
||||||
webapp.Get("/delete/:name", app.Delete(pool))
|
webapp.Get("/delete/:name", app.Delete(pool))
|
||||||
|
webapp.Put("/pause/:name", app.Pause(pool))
|
||||||
|
webapp.Put("/start/:name", app.Start(pool))
|
||||||
|
|
||||||
webapp.Post("/knowledgebase", app.KnowledgeBase(db))
|
webapp.Post("/knowledgebase", app.KnowledgeBase(db))
|
||||||
webapp.Post("/knowledgebase/upload", app.KnowledgeBaseFile(db))
|
webapp.Post("/knowledgebase/upload", app.KnowledgeBaseFile(db))
|
||||||
|
|||||||
@@ -40,6 +40,12 @@
|
|||||||
<th scope="col" class="px-6 py-3 text-center">
|
<th scope="col" class="px-6 py-3 text-center">
|
||||||
<span class="sr-only">Talk</span>
|
<span class="sr-only">Talk</span>
|
||||||
</th>
|
</th>
|
||||||
|
<th scope="col" class="px-6 py-3 text-center">
|
||||||
|
<span class="sr-only">Start</span>
|
||||||
|
</th>
|
||||||
|
<th scope="col" class="px-6 py-3 text-center">
|
||||||
|
<span class="sr-only">Stop</span>
|
||||||
|
</th>
|
||||||
<th scope="col" class="px-6 py-3 text-center">
|
<th scope="col" class="px-6 py-3 text-center">
|
||||||
<span class="sr-only">Delete</span>
|
<span class="sr-only">Delete</span>
|
||||||
</th>
|
</th>
|
||||||
@@ -47,10 +53,12 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody class="bg-gray-800 divide-y divide-gray-700">
|
<tbody class="bg-gray-800 divide-y divide-gray-700">
|
||||||
<!-- Dynamic agent rows go here -->
|
<!-- Dynamic agent rows go here -->
|
||||||
|
{{ $status := .Status }}
|
||||||
{{ range .Agents }}
|
{{ range .Agents }}
|
||||||
<tr hx-ext="sse">
|
<tr hx-ext="sse">
|
||||||
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-300">{{.}}</td>
|
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-300">{{.}}</td>
|
||||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-300">
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-300">
|
||||||
|
Online: {{ index $status . }}
|
||||||
<a href="/status/{{.}}" class="text-indigo-500 hover:text-indigo-400">
|
<a href="/status/{{.}}" class="text-indigo-500 hover:text-indigo-400">
|
||||||
<i class="fas fa-info"></i> Status
|
<i class="fas fa-info"></i> Status
|
||||||
</a>
|
</a>
|
||||||
@@ -60,6 +68,16 @@
|
|||||||
<i class="fas fa-comments"></i> Talk
|
<i class="fas fa-comments"></i> Talk
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
|
<td class="px-6 py-4 whitespace-nowrap text-center text-sm font-medium">
|
||||||
|
<button hx-put="/start/{{.}}" class="text-indigo-500 hover:text-indigo-400">
|
||||||
|
Start
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
<td class="px-6 py-4 whitespace-nowrap text-center text-sm font-medium">
|
||||||
|
<button hx-put="/pause/{{.}}" class="text-indigo-500 hover:text-indigo-400">
|
||||||
|
Pause
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
<td class="px-6 py-4 whitespace-nowrap text-center text-sm font-medium">
|
<td class="px-6 py-4 whitespace-nowrap text-center text-sm font-medium">
|
||||||
<a href="/delete/{{.}}" class="text-red-500 hover:text-red-400">
|
<a href="/delete/{{.}}" class="text-red-500 hover:text-red-400">
|
||||||
<i class="fas fa-trash-alt"></i> Delete
|
<i class="fas fa-trash-alt"></i> Delete
|
||||||
|
|||||||
Reference in New Issue
Block a user