Skip to content

Conversation

@cneuralnetwork
Copy link

Fixes Issue #44

  • Removed frozen dataclass constraint - Changed from @dataclass(frozen=True to @dataclass to allow mutable state tracking
  • Added _last_state instance variable

Usage

from prompt_siren.agents.plain import PlainAgent, PlainAgentConfig
import asyncio
async def main():
    agent = PlainAgent(
        _config=PlainAgentConfig(model="openai:gpt-4.1-mini")
    )
    try:
        result = await agent.run(
            environment=env,
            env_state=state,
            user_prompt="Long running task...",
            toolsets=toolsets,
        )
        return result
    except asyncio.CancelledError:
        last_state = agent.get_last_state()
        if last_state:
            print(f"Messages exchanged: {len(last_state.run_ctx.messages)}")
            print(f"Tokens used: {last_state.run_ctx.usage.total_tokens}")
        raise
if __name__ == "__main__":
    asyncio.run(main())

Tests Done

  • checks that the correct partial state is returned when execution is cancelled mid-iteration.
  • checks that None is returned when execution is cancelled before any state is produced.
  • checks that the final state is correctly tracked during normal, non-cancelled execution.
  • checks that token usage metrics are preserved in the captured state when execution is cancelled.
  • checks that message history is preserved in the partial state, including any pre-existing messages.
image

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Dec 19, 2025
@cneuralnetwork
Copy link
Author

Hey! @dedeswim
Implemented #44
Please check once :)

@dedeswim
Copy link
Collaborator

Thanks for the contribution! The AbstractAgent implementations are stateless, and we would like to keep them that way. Is there a different approach that can be taken for this?

Also, there are some conflicts that should be solved

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

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants