GitHub Offers Five Python Scripts for an AI Agent

Five Python scripts available on GitHub allow for the construction of an AI agent, from the action loop to human supervision. Each includes an offline mode, accessible with --mock or --demo without an API key, before connecting to a model of choice.
Human control filters risky actions
Writing a file, deleting an item, or sending an email can have concrete consequences when an agent calls the wrong tool. The supervision script thus places a control between the request generated by the model and its execution. Each tool receives a risk classification, while decisions feed into an audit log.
A deemed safe operation proceeds immediately; a blocked operation never goes through. The intermediate level awaits a response of y, n, or a, with the latter representing permanent authorization. For high-risk operations, a yes input is required. In the absence of possible input, execution is denied.
The denial returns to the model in the form of a tool result, accompanied, if necessary, by a human instruction, such as choosing a different file name. The agent can thus adapt its request instead of repeating it without considering the opposition. In this example, file operations remain confined to the working directory; messaging sends nothing but writes to a file.
Memory retains exchanges between sessions
A stateless model only retrieves previous exchanges if they are transmitted to it again. Resending everything has a cost and can saturate the available context; deleting history also removes information. The local manager thus allocates memory between recent exchanges, a summary of previous ones, and enduring facts added by /remember. These elements reside in a JSON file retained after a restart.
When recent exchanges exceed their token budget, the oldest ones exit this window after being integrated into the summary. The cutoff is adjusted so that the first retained message comes from the user, as required by the API. The enduring facts are selected based on keywords shared with the current request: only the retained elements join the system instruction.
The recording goes through a temporary file, followed by the replacement of the memory file, to prevent a sudden stop from corrupting the backup. The component responsible for summarizing remains interchangeable. The demonstration proceeds through simple extraction; a language model can take on this function for real conversations.
The AI brief the pros read every evening
The 7 best AI stories, the essentials in 5 min. Free.
Included when you join: our pick of the best AI guides & comparisons.
Choose your rhythm
Free · No spam · Unsubscribe in 1 click
Pydantic AI checks tickets before submission
An absent field or a priority expressed differently than expected can cause the processing that follows a model response to fail. The customer support example imposes a Pydantic model comprising category, priority, summary, sentiment, escalation indicator, and tags. It returns a Python object, not text left for interpretation.
The parameter output_type=TicketTriage provides the schema to the model, then Pydantic AI checks each response. In case of non-compliance, the error returns to the model for correction, with a bounded number of retries. An additional check, @output_validator, imposes a business rule distinct from the schema: any critical ticket must be escalated. The simulation intentionally begins with two incorrect responses before producing a compliant one, making visible the number of retries necessary.
ReAct limits exchanges with tools
The agentic operation consists of choosing an action, mobilizing a tool, examining its return, and continuing until the task is completed. The ReAct example makes this loop explicit in pure Python: the model formulates a thought, designates a tool, and then receives the result as an observation. It has access to a calculator, a word count tool, and a date search.
The response must adhere to imposed sections for thought, action, and its input data. A stop sequence triggered by Observation: leaves the program, rather than the model, to produce the tool result. Regular expressions control the format; if it is incorrect, the model receives feedback and can correct its response.
The calculator interprets expressions with ast, without resorting to eval, to prevent arbitrary code execution. The loop concludes with a final response or the ceiling set by max_steps. This method engages the model at each step and does not provide a complete view of the planned sequence before the action.
The planner corrects its steps after failure
To analyze a CSV, another script prepares all operations before launching them. This preliminary plan can be incorrect, as it precedes the observation of the data. The model provides it as a JSON array; the program checks the mentioned tools, the exact match of arguments, and the step ceiling before any execution. A non-compliant plan returns once with the reason for rejection.
The executor uses ordinary Python and does not query the model during operations. When a tool fails, a specific error conveys a usable indication, such as the columns that are actually available. The model then receives the summary of actions already taken and the failure to revise only the remaining work. The demonstration precisely triggers this situation with a non-existent column.
The resumption allows for two attempts at replanning, while a global step limit also halts sequences of incorrect plans. Access to files remains limited to the working directory. Once operations are completed, the model produces a brief report based on the results collected.
Brief AI — AI news in French
The essentials of artificial intelligence news, decoded and explained every day.