Skip to content

[BUG] mis-order of structured_output_span #692

@chengweitsai

Description

@chengweitsai

Checks

  • I have updated to the lastest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Strands Version

1.5.0

Python Version

3.10.18

Operating System

macOS 15.5

Installation Method

pip

Steps to Reproduce

llm = OpenAIModel(
    client_args={
        "api_key": os.getenv("API_KEY"),
        "base_url": os.getenv("BASE_URL"),
    },
    model_id=os.getenv("MODEL_ID"),
    params={
        "max_tokens": int(os.getenv("MAX_TOKENS", 1000)),
        "temperature": float(os.getenv("TEMPERATURE", 0.7)),
    },
)

agent = Agent(
    model=llm,
    system_prompt="You are a helpful assistant.",
    trace_attributes={
        "session.id": f"vrt-{str(uuid.uuid4())}",
    },
    name="SimpleAgent",
)


class CityInfo(BaseModel):
    city: str
    country: str
    population: Optional[int] = None
    climate: str


agent.structured_output(CityInfo, "Provide some information about Taipei")

Expected Behavior

Input trace message should be:

[
    {
        "role": "system",
        "content": [
            {
                "text": "You are a helpful assistant."
            }
        ]
    },
    {
        "role": "user",
        "content": [
            {
                "text": "Provide some information about Taipei"
            }
        ]
    }
]

Actual Behavior

[
    {
        "role": "user",
        "content": [
            {
                "text": "Provide some information about Taipei"
            }
        ]
    },
    {
        "role": "system",
        "content": [
            {
                "text": "You are a helpful assistant."
            }
        ]
    }
]

Additional Context

Image

Possible Solution

As mentioned in https://github.com/strands-agents/sdk-python/pull/655/files#r2284600702

Move the system_prompt before messages.

Related Issues

#655

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions