Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat: move initial prompt to conversation
  • Loading branch information
35C4n0r committed Oct 2, 2025
commit db3af7b3cb264b5cef38004c4e862a999c45fec4
52 changes: 24 additions & 28 deletions lib/httpapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,17 @@ import (

// Server represents the HTTP server
type Server struct {
router chi.Router
api huma.API
port int
srv *http.Server
mu sync.RWMutex
logger *slog.Logger
conversation *st.Conversation
agentio *termexec.Process
agentType mf.AgentType
emitter *EventEmitter
chatBasePath string
initialPrompt string
initialPromptSent bool
router chi.Router
api huma.API
port int
srv *http.Server
mu sync.RWMutex
logger *slog.Logger
conversation *st.Conversation
agentio *termexec.Process
agentType mf.AgentType
emitter *EventEmitter
chatBasePath string
}

func (s *Server) NormalizeSchema(schema any) any {
Expand Down Expand Up @@ -233,20 +231,18 @@ func NewServer(ctx context.Context, config ServerConfig) (*Server, error) {
SnapshotInterval: snapshotInterval,
ScreenStabilityLength: 2 * time.Second,
FormatMessage: formatMessage,
})
}, config.InitialPrompt)
emitter := NewEventEmitter(1024)
s := &Server{
router: router,
api: api,
port: config.Port,
conversation: conversation,
logger: logger,
agentio: config.Process,
agentType: config.AgentType,
emitter: emitter,
chatBasePath: strings.TrimSuffix(config.ChatBasePath, "/"),
initialPrompt: config.InitialPrompt,
initialPromptSent: len(config.InitialPrompt) == 0,
router: router,
api: api,
port: config.Port,
conversation: conversation,
logger: logger,
agentio: config.Process,
agentType: config.AgentType,
emitter: emitter,
chatBasePath: strings.TrimSuffix(config.ChatBasePath, "/"),
}

// Register API routes
Expand Down Expand Up @@ -314,11 +310,11 @@ func (s *Server) StartSnapshotLoop(ctx context.Context) {
currentStatus := s.conversation.Status()

// Send initial prompt when agent becomes stable for the first time
if !s.initialPromptSent && convertStatus(currentStatus) == AgentStatusStable {
if err := s.conversation.SendMessage(FormatMessage(s.agentType, s.initialPrompt)...); err != nil {
if !s.conversation.InitialPromptSent && convertStatus(currentStatus) == AgentStatusStable {
if err := s.conversation.SendMessage(FormatMessage(s.agentType, s.conversation.InitialPrompt)...); err != nil {
s.logger.Error("Failed to send initial prompt", "error", err)
} else {
s.initialPromptSent = true
s.conversation.InitialPromptSent = true
currentStatus = st.ConversationStatusChanging
s.logger.Info("Initial prompt sent successfully")
}
Expand Down
8 changes: 7 additions & 1 deletion lib/screentracker/conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ type Conversation struct {
messages []ConversationMessage
screenBeforeLastUserMessage string
lock sync.Mutex
// InitialPrompt is the initial prompt passed to the agent
InitialPrompt string
// InitialPromptSent keeps track if the InitialPrompt has been successfully sent to the agents
InitialPromptSent bool
}

type ConversationStatus string
Expand All @@ -94,7 +98,7 @@ func getStableSnapshotsThreshold(cfg ConversationConfig) int {
return threshold + 1
}

func NewConversation(ctx context.Context, cfg ConversationConfig) *Conversation {
func NewConversation(ctx context.Context, cfg ConversationConfig, initialPrompt string) *Conversation {
threshold := getStableSnapshotsThreshold(cfg)
c := &Conversation{
cfg: cfg,
Expand All @@ -107,6 +111,8 @@ func NewConversation(ctx context.Context, cfg ConversationConfig) *Conversation
Time: cfg.GetTime(),
},
},
InitialPrompt: initialPrompt,
InitialPromptSent: len(initialPrompt) == 0,
}
return c
}
Expand Down
4 changes: 2 additions & 2 deletions lib/screentracker/conversation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func statusTest(t *testing.T, params statusTestParams) {
if params.cfg.GetTime == nil {
params.cfg.GetTime = func() time.Time { return time.Now() }
}
c := st.NewConversation(ctx, params.cfg)
c := st.NewConversation(ctx, params.cfg, "")
assert.Equal(t, st.ConversationStatusInitializing, c.Status())

for i, step := range params.steps {
Expand Down Expand Up @@ -147,7 +147,7 @@ func TestMessages(t *testing.T) {
for _, opt := range opts {
opt(&cfg)
}
return st.NewConversation(context.Background(), cfg)
return st.NewConversation(context.Background(), cfg, "")
}

t.Run("messages are copied", func(t *testing.T) {
Expand Down