Skip to content

Commit

Permalink
ais: agent sef-repair
Browse files Browse the repository at this point in the history
  • Loading branch information
fwbrasil committed Dec 22, 2023
1 parent c7968f8 commit 31a6801
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
16 changes: 12 additions & 4 deletions kyo-llm/shared/src/main/scala/kyo/llm/agents.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kyo.seqs._
import kyo.tries._
import kyo.locals._
import kyo.llm.ais._
import kyo.llm.thoughts.reasoning._
import scala.util._
import kyo.llm.contexts._
import kyo.concurrent.atomics._
Expand Down Expand Up @@ -99,10 +100,11 @@ package object agents {
}

private[kyo] def handle(ai: AI, agents: Set[Agent], calls: List[Call]): Unit < AIs =
Seqs.traverseUnit(calls) { call =>
Seqs.traverse(calls) { call =>
agents.find(_.info.name == call.function) match {
case None =>
ai.agentMessage(call.id, "Agent not found: " + call)
ai.agentMessage(call.id, "Agent doesn't exist anymore: " + Json.encode(call))
.andThen(false)
case Some(agent) =>
AIs.ephemeral {
Agents.disable {
Expand All @@ -120,11 +122,17 @@ package object agents {
}
}.map {
case Success(result) =>
ai.agentMessage(call.id, result)
ai.agentMessage(call.id, result).andThen(true)
case Failure(ex) =>
ai.agentMessage(call.id, "Failure:" + ex)
ai.agentMessage(call.id, "Agent failure:" + ex).andThen(false)
}
}
}.map { l =>
if (!l.forall(identity)) {
ai.gen[Repair]("One or more agents failed.").unit
} else {
()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package kyo.llm.thoughts.reasoning

import kyo.llm.ais._

@desc(
p"""
The Repair thought is used for introspection and correction following errors in the LLM's reasoning or output.
- Focuses on analyzing recent actions to identify the causes of failures.
- Aims to develop strategies to prevent similar errors in future reasoning processes.
- Encourages the LLM to critically evaluate its performance and apply corrective measures.
- This thought is crucial for the LLM's learning process, allowing it to adapt and improve over time.
- Example: If an error is detected in JSON generation, Repair directs the LLM to pinpoint the error's source and
modify its approach to ensure compliance with JSON standards.
"""
)
case class Repair(
`Analyze recent actions to identify failure causes`: String,
`Develop strategies to avoid similar errors`: String,
`Elaborate on the corrective measures to be applied`: String
)

0 comments on commit 31a6801

Please sign in to comment.