learning-it by example

#249 Enterprise architecture and AI agents 6.1 min

Build a Minimal AI Agent Platform: Gateway, Registry, Audit

I built an agent platform in 100 lines, and switched an agent off by changing one flag in the registry.

1. In the minimal agent platform, how was the billing bot turned off without changing any code?
2. In the Python minimal agent platform (registry, gateway, budget, audit log), how many of the nine test calls were done and how many were stopped?
3. Which status code does the gateway return when an agent would go over its daily budget?
4. Why does each line of the audit log carry a short hash of the line before it?
5. A gateway for agent tools is only useful under one condition. What is it?

Practice only: nothing is saved and no score counts towards anything. Each answer comes with the reason.

  1. Predict the nine calls

    Copy the code folder first. Read the CALLS list in compare.py and the checks in core.py. Write down the status code you expect for each of the nine calls, then run python compare.py and compare. You should see 4 of 9 calls were done.

    A hint

    The checks run in order: registered, active, tool exists, scope, budget.

  2. Give the support agent more budget

    In compare.py, change the support agent budget from 4.0 to 6.0. Predict which call changes, then run python compare.py. You should see 5 of 9 calls were done, 4 stopped, with the refund for cat now done and the refund for dan still refused for budget. Then change 6.0 back to 4.0 before the next task.

    A hint

    A read costs 0.5 and a refund costs 2.0, as set in the TOOLS table in core.py.

  3. Grant a missing scope

    In compare.py, add "email:send" to the scopes of the support agent. Run python compare.py and find the call that changes. The send_email call for ana should now be done, and the total should be 5 of 9. Then remove it again before the next task.

    A hint

    The scopes are a set inside the Agent line for support-agent.

  4. Tamper with the audit log

    In compare.py, just before the line registry.suspend("billing-bot"), add this line: audit.lines[2] = audit.lines[2].replace("403", "200"). Run python compare.py and read the last line, which should say chain intact: False. Then move the edit to change audit.lines[-1] after the last call and see what the check says about the final line.

    A hint

    The final line has no later line carrying its hash, so think about what the check can compare it with.

These tasks are for you to try on your own machine. Nothing is checked or saved.

What this does not show

A teaching platform in one process and in memory: no real caller identity, no database, a budget counter that never resets, a hash chain that cannot see changes to its last line, and nothing here stops an agent going round the gateway.

Up next in Enterprise architecture and AI agents

More in Enterprise architecture and AI agents

All Enterprise architecture and AI agents videos

Related videos