AI Hero Club

AI Agent Engineering · Lesson 3

Marked Complete by You0 / 8

Saved in this browser only. Marking a lesson complete does not mean the project has passed verification.

Lesson Outline 8 subsections
Course Contents 8 lessons
Full course plan.
AI Agent Engineering / Learning Plan ↗

LESSON 03 / 8Suggested study 120 minutes

Policy Interfaces, Budgets and Provable Stopping

How can we replace an agent’s decision source while guaranteeing that repeated proposed actions cannot make a task run forever?

3 Questions for This Lesson
  • Realization of the three real policy sources and maintenance of the same enforcement compact
  • Inference to budget and retest upper bounds
  • Verifying the end action must be supported by evidence and not ultra vires
Course Project ZIP ↓

Separate Decision Quality from Execution Reliability

The first two chapters already have real tools and recoverable status. The policy interface now has one thing to do: accept the current observable state and propose one. JSON Actions. Default DeterministicPolicy selects a fixed chain based on structured tasks and observations already in place; LocalJSONPolicy reads from the file action list to a sustained decision number; HTTPJSONPolicy sends to the specified address JSON Status and read the next action. All three really do and can be called, not empty, class definitions. They share value_action and anthorize, and external responses cannot skip permissions, targets and versions.

The research value of defaulting workflows is to create a repeatable baseline, not simulated general reasoning. It selects the next step based on the only search hits, access to information, permissions, inventories and feedback, without learning to plan. Research models such as ReAct refer to the reasoning of environmental feedback, and this course refers only to its problem background and does not claim the ability of the current branch of rules to reproduce papers. To be included, the same HTTP protocol or replacement next_action can be achieved externally, subject to re-evaluation of mission success, cost and boundaries; The implementation of the base has become credible through a strategy that does not amount to new.

Interface Inputs Must Be Observations, Not Mutable Execution Handles

Runner transmits a deep copy of the state to policy to prevent a local policy from directly modifying observations, calls or allow_write to falsify history. The policy does not see database connections or executive functions, but only returns action proposals. HTTP adapter sends protocol to hero-policy-v1 and view, which still contains tasks, observations, feeding and counting, and the receiving end returns a single action object. External services can generate actions using models, rules, or manual programs. The protocol does not require a vendor format, nor does it imply that the model has been called.

The local JSON policy file is a list of actions. After each tool action, the decisions plus one will be restored to read the next position; the pending strategy will not be visited again during the re-try to avoid the new strategy giving another set of numbers or buttons. The list is depleted and returns to abstain to avoid indexing when it crosses the border. It is suitable for contractual testing and replayable action scripts, and cannot be adapted to new observations and therefore does not replace dynamic strategies. The project test completes the camera preset with a full five action list, proving that it is not only capable of producing a rejection action.

The Boundaries of the HTTP Adapter

HTTPJSONPolicy executable via standard library urllib POST, request type application/json "A timeout, a maximum of 65,536 bytes." JSON content type. The same action check is done immediately after the analysis. To avoid an explicit external transmission, normal HTTP Only ring addresses are allowed. Other addresses are required. HTTPS ; URL. The remote service addresses are clearly configured and do not come from the device text. The request can be accessed by the caller, but the key will not be entered into the task snapshot or public evidence in the course.

The contract test actually starts temporary HTTP service on this machine: the service is received in a state where the default rules are used to generate the action and return to JSON; the client completes four tools with one end action by five HTTP round-trips. It verifies sequencing, transmission, response resolution and implementation of integration without verifying remote model reasoning, supplier availability or Internet delay. The first sandbox prohibits listening back to the loop port, recording it as an environmental block; allows all 16 checks after the test to pass. The evidence retains this failed process and does not replace the non-operational remote capability with success.

Budgets Are Executor Constraints, Not Prompt Suggestions

Try to cap the tool on K, and the current tool on c. Each time you really launch a call, check c is less than K, then lasts c plus one, then calls. Failed also consumes once because it takes up actual resources and uncertainty once. End action does not consume tools; policy_error The current strategy ends with either an action that ultimately leads to calls or errors, and therefore does not call tools indefinitely for limited K and limited single execution time. HTTP waits for another timeout and the local Python tool still requires process-level isolation if permanently blocked, and the project has no generic ability to force the suspension of any code.

0≤c≤K,Apending≤R+10\leq c\leq K,\qquad A_{pending}\leq R+1
c For total tool attempts, K is the upper limit; A_pending is a cumulative attempt for current actions, and R is not called a retry for the first time to allow repeated trials. The global budget can be depleted first.

The number of tools is not the model token cost, not the total number of seconds for wall clocks, or the number of transactional effects. The current call cap and the maximum limit for each action retest are actually performed; the remote model 's token, money and end-to-end time periods are not accounted for and cannot be said to be “The cost is completely controlled.”. If you have access to the pay-as-you-go model, the model should be requested, responded to to to token, the source of costs and the duration state, and a scale check should be done before the call.

Worked Example 1: Exactly Four Calls and Normal Completion

Camera preset requires four calls from search, document, stock, reserv. K equals four, R equals two. After the fourth success c, the strategy is set to four, based on reserv observations, and the executor validates and writes termination status. If the “cequalsK” is considered to be all actions immediately ending, the mark bugget_exhausted; The correct approach is to allow a legal end first, and only check the amount when preparing the next tool. Project-budget fixed tasks and unit tests cover this boundary together. The original result is reserved, calls are four, effect book entry.

Same job if K equals two, there is a lack of inventory and services after reading the information. The next action would have been a stock, but the pre-call budget check failed, the status of the bugget_exhausted was unchanged. The stock cannot be skipped to improve the completion rate or the default of an unexecuted preset could not be written; nor could it be automatically increased K The budget is not a negative business, but only a statement that the current implementation is not being carried out within the given resources. The report should retain the observations collected for the purpose of continuing to design the new and clearly defined tasks, rather than treating them as missing.

Worked Example 2: The Policy Declares Completion Too Early

Assuming that the external service returns the finish reserved as a first step, there are no tools to observe. The action structure is completely legal, and the status is allowed in the list, but the finalize can't find the reserve observation, you should throw the unsupported financial status into policy_error; the account book is zero. If you return the finishinfo, you must also have the only hits and files available under the Info task. The policy selects abstain for the moment, but cannot create facts by using a sentence “Completed”. This limits the freedom to replace models to action selection, and the implementer still holds the conditions for completion.

Standalone ProgramIndependent logical check: limit instruments only and de facto restraint limits end.
def classify(calls,limit,action):
    if action=='finish_supported':return 'finished'
    if action=='finish_unsupported':return 'policy_error'
    return 'call' if calls<limit else 'budget_exhausted'
assert classify(4,4,'finish_supported')=='finished'
assert classify(4,4,'tool')=='budget_exhausted'
assert classify(0,8,'finish_unsupported')=='policy_error'
K,R=4,2
assert min(K,R+1)==3
print('budget and stopping checks PASS')

Safety and Liveness of Stopping Conditions

The security character description does not occur, for example, without authorization to write a inventory, unknown tools are not executed, and no observation is not known as pre-set. The active nature describes what happens when the premises are met, such as when the tools are limited, when they return, when the strategy is legitimate and when the budget is adequate, and when the normal mission ceases. Only security is not active, the system may always be abstain; only activity is not safe, the system may be successful in completing it as soon as possible. This project’s fixed tasks include both completion, rejection and budgetary discontinuation, avoiding a general success label to mask these differences.

The first type of validation is interface replacement: the default, local JSON and the real loop HTTP are all in the same tool chain and the results, inventories and references are consistent. The second category is counter-decision-making: unknown tools, unauthorized writing, early ending and budget boundaries must be blocked by the executor. The interface test does not prove that the system has been integrated if only two hundred copies of HTTP are received without looking at the database effect. The current remote LLM is not running, so the course does not provide a language model success rate, nor does the local rules pass rate benchmark.

The network also needs to be separated from the entire mandate by time of overtime. The urllib timeeout network is waiting for operations that do not amount to a global closure from the start to the end of the mission; services that continue to return slowly should still be recorded at a higher level and implemented in isolation, which can be cancelled. The current aircraft contract service is limited and quickly returned, and the course only validates the scope. The budget proves that the use of “Back when each action is limited” is an explicit premise that no wall clocks for any outside service can be rolled out from K to a limited extent.

The action in the policy file is also re-checked, and it cannot be trusted by default because it is stored on this machine. Offline files, HTTP responses share the same door locks as default rules, so that interface replacement does not change execution privileges.

Exercises and Project Contributions

TRY IT YOURSELF

Foundation: Try and retry

R=2 means several attempts at most? Can you try three times at K=2?

Hint 1
The first attempt was distinguished from the additional re-testing and the global call to budget was superimposed.
Hint 2
A partial attempt cap and a K cap are written separately, which can only be met simultaneously, without retesting being considered free.
Compare with the Solution
It is only allowed twice in the total budget.

TRY IT YOURSELF

Step: The adaptor contract

HTTP returns 200 text with “Please call.reserve”. Why not execute it directly?

Hint 1
What content and business verifications are to be passed in turn after successful HTTP transmission?
Hint 2
The tasks and pre-conditions are first checked for the Fontent-Type and JSON action structures; the natural language action proposal is not automatically executed.
Compare with the Solution
The protocol requires that application/json and the object that corresponds to the structure of the action are not legal. Even if JSON is legally required to verify the scope of the task and the pre-checking. To overwrite the resolution, structure and effect, the success of the HTTP state does not mean that the business action is authorized.

TRY IT YOURSELF

The challenge: proving the border

Why does limited K not automatically guarantee that any local tool will stop at limited wall clock hours? How should it be honest?

Hint 1
Does the limited number of calls set a threshold for each call?
Hint 2
Construct a local tool that will never return at once, and compare HTTP to whether the mandatory termination of the Python process has been achieved.
Compare with the Solution
A tool can permanently block or run an unlimited cycle per se, with a limited number of calls not limiting a single time. This project tool is limited in local reading and writing, HTTP is time-consuming, but it does not isolate and kill any Python function. The universal system should increase process duration, cancel and unconfirmed effects processing; currently only states that the agreed tool and interface conditions will stop.

This chapter adds three categories of policy, uniform action validation, and completion conditions. The next chapter will temporarily remove the strategy and direct analysis tools to refer to the identity in failure and retry: when a repeat request is safe, and when stockpiles are held back. Policy, whether from a model or from a rule, has to follow the same semantic meaning as durable.

CHECK YOUR UNDERSTANDING

Check Your Understanding

Answer first, then open the explanation to check your reasoning. These questions help reveal gaps in understanding; independent implementation and transfer require separate evaluation.

What did you get from 1. policy?

Show ExplanationIt merely proposes actions, and enforcement remains under the control of Runner.
2. HTTP mainframe test proves what?

Show ExplanationThe server is a home-office certainty strategy and cannot extrapolate model capabilities.
3. Having reached the upper limit for callbacks, is there enough observation?

Show ExplanationEnding the call without using the tool, but it must be supported by evidence.
4. Who enforces the budget?

Show ExplanationThe suggestion cannot be a substitute for the ban on actual resources.

Manual completion records your progress; it does not certify your project.