Skip to content

Commit 5e8d702

Browse files
authored
Merge pull request #247 from krissetto/max-iterations-on-server-sesssion
Add max iterations to server session
2 parents dc965db + 8d78ab0 commit 5e8d702

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pkg/server/server.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ func (s *Server) createSession(c echo.Context) error {
775775
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid request body"})
776776
}
777777

778-
sess := session.New()
778+
sess := session.New(session.WithMaxIterations(sessionTemplate.MaxIterations))
779779
sess.ToolsApproved = sessionTemplate.ToolsApproved
780780

781781
if err := s.sessionStore.AddSession(c.Request().Context(), sess); err != nil {
@@ -843,12 +843,17 @@ func (s *Server) runAgent(c echo.Context) error {
843843

844844
t, exists := s.teams[agentFilename]
845845
if !exists {
846-
return c.JSON(http.StatusNotFound, map[string]string{"error": fmt.Sprintf("runtime not found: %s", agentFilename)})
846+
return c.JSON(http.StatusNotFound, map[string]string{"error": fmt.Sprintf("team not found: %s", agentFilename)})
847847
}
848848
sess, err := s.sessionStore.GetSession(c.Request().Context(), sessionID)
849849
if err != nil {
850850
return c.JSON(http.StatusNotFound, map[string]string{"error": "session not found"})
851851
}
852+
// Only set max iterations the first time the session is run
853+
// since on creation we can accept an empty sessionTemplate
854+
if len(sess.Messages) == 0 && sess.MaxIterations == 0 && t.Agent(currentAgent).MaxIterations() > 0 {
855+
sess.MaxIterations = t.Agent(currentAgent).MaxIterations()
856+
}
852857

853858
rt, exists := s.runtimes[sess.ID]
854859
if !exists {

0 commit comments

Comments
 (0)