Skip to content

Conversation

@rmay1er
Copy link

@rmay1er rmay1er commented Dec 18, 2025

Bug description

agent.Generate returned an error when prompt was empty, even if user input
was already provided via the messages slice. This caused valid usage patterns
to fail unexpectedly.


Steps to reproduce (before)

		// Call the AI client to generate a response using the conversation messages.
		// Convert memorybox messages into the format expected by the AI client.
		resp, err := agent.Generate(ctx, fantasy.AgentCall{
			// Prompt:   input, // Was Error because empty.
			Messages: convert.ToFantasy(userMsgs),
		})
		if err != nil {
			// Print AI generation errors and stop.
			fmt.Printf("Generation error: %v\n", err)
			break
		}

Result:

error: prompt can't be empty

Expected behavior

If user input is already present in messages, an additional prompt string
should not be required.

Fix

•	Updated validation logic to return an error only when both prompt is empty and no messages are provided
•	Preserved existing system prompt resolution logic:
•	system message from messages is used when present
•	explicit system argument still overrides it

Result (after)

The same call now produces a valid prompt without returning an error.

Notes
• No breaking changes
• No public API changes
• CI and examples pass


  • I have read CONTRIBUTING.md.
  • I have created a discussion that was approved by a maintainer (for new features).

- Infer system from first system message when present
- Append user message only when prompt is non-empty
@rmay1er rmay1er changed the title Fix/empty prompt fix(errors): empty prompt logic Dec 18, 2025
Comment on lines +997 to +998
if len(messages) > 0 && messages[0].Role == MessageRoleSystem {
if len(messages[0].Content) > 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably iterate over all messages and collect system role messages, + all message content instead of just the first message.

preparedPrompt = append(preparedPrompt, messages...)
preparedPrompt = append(preparedPrompt, NewUserMessage(prompt, files...))

if prompt != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if prompt is empty we should guard that the last message in the message list is a user message, or a tool response.

I think its not expected that we send a message with the last message being an assistant message.

@kujtimiihoxha
Copy link
Member

This seems to be also related to #59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants