Log in to leave a comment
No posts yet
You can finally stop running your own Redis instances or piling up text logs in your database just to manage per-user conversation history. For startup developers overwhelmed by infrastructure management, pushing the entire context into the model every time is simply a waste of tokens and an accumulation of operational debt. Anthropic Managed Agents store event logs on the server side using a single session_id.
It is simple. All you need to do is create one anthropic_session_id column in your existing users table. When a user connects, if this ID is empty, call the API to create a new session and store it in the DB. If an ID already exists, simply pass that value to resume the session.
Refactoring with this method reduces server resource costs by more than 40%. Not only do DB I/O operations naturally decrease, but prompt caching efficiency is also maximized, causing the cost of input tokens—which used to be sent redundantly every time—to noticeably vanish. Compared to the cost of hosting your own server to maintain context, the operational burden becomes virtually zero.
When granting an agent permissions for Notion or GitHub, the most horrific scenario is an API key leak. Keeping keys in server environment variables means all permissions could be compromised with a single prompt injection. Managed Agents use a proxy model called Credential Vault, ensuring that even the agent itself never sees the actual key values.
If you care about security, create independent Vault instances for each project. When registering external service API keys in the Vault, you must configure them so that sensitive data is never included in the response values. By simply specifying vault_ids when starting a session, Anthropic's infrastructure automatically injects the keys into the request headers.
This eliminates the need to store keys on local servers, removing security risks. In particular, Managed Agents handle tedious tasks like OAuth token refreshing automatically, so developers don't need to write complex logic. This lowers the probability of security incidents by more than 90% while making integration much more convenient.
Convenience comes at a price. Managed Agents charge a runtime fee of $0.08 per hour while a session is active. This means if you leave them alone, money is leaking out. However, since charges do not apply during idle time, you need middleware that strictly manages the session lifecycle.
To save costs, apply three automation strategies. First, if there is no user input for 15 minutes, immediately switch the session to an idle state and set it to auto-archive after 1 hour. Second, background tasks should terminate and delete the session as soon as they produce a result. Third, set a monthly spending limit in the Anthropic Console to fundamentally block unexpected session spikes.
Reducing the active time is the key. In practice, properly implementing idle time management logic can save an additional 25% of total operating costs.
If agent responses are sluggish, users will leave immediately. While Managed Agents reduce processing time by up to 85% through prompt caching, you must personally address the Cold Start time that occurs when first launching a session.
To pull the response speed forward by more than 2 seconds, query the existing session as soon as you receive the user_id and start the SSE (Server-Sent Events) connection immediately. Designing system prompts to be over 1,024 tokens is another effective method. This activates prompt caching, dropping the Time to First Token (TTFT) from around 2.2 seconds to the 0.8-second range.
If the agent sends a signal that it has stalled during a tool call, the backend handler must intercept this and resume the conversation immediately. By adding this type of exception handling and self-correction logic, the success rate for complex tasks increases by more than 10 percentage points. This is how you create an environment where you can focus on business logic without worrying about infrastructure.