Skip to content

[FEATURE] Support adding prompts to conversational history when using structured output #810

@dwu12

Description

@dwu12

Problem Statement

I would like Strands to add prompt to conversational history when using structured output method. I followed the example code:

agent = Agent()

# Build up conversation context
agent("What do you know about Paris, France?")
agent("Tell me about the weather there in spring.")

# Extract structured information with a prompt
class CityInfo(BaseModel):
    city: str
    country: str
    population: Optional[int] = None
    climate: str

# Uses existing conversation context with a prompt
result = agent.structured_output(CityInfo, "Extract structured information about Paris")

However the agent messages only contain the first two queries: "What do you know about Paris, France?", "Tell me about the weather there in spring." without adding the prompt "Extract structured information about Paris" in the history.

Can we add this feature to the history? For example convert structured class into json file and store both (prompt and json output to the conversational history)

Proposed Solution

No response

Use Case

See above. For example, for use case requires query decomposition + query rewriting as the first step, I would like directly use agent.structured_output() to generate sub queries. However, If I have a follow up question, it won't work because the previous prompt wasn't stored in conversational history.

Alternatives Solutions

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions