We’ll cover how actions are represented (using JSON or code), the importance of the stop and parse approach, and introduce different types of agents.
Actions are the concrete steps an AI agent takes to interact with its environment.
Whether it’s browsing the web for information or controlling a physical device, each action is a deliberate operation executed by the agent.
For example, an agent assisting with customer service might retrieve customer data, offer support articles, or transfer issues to a human representative.
There is multiple types of Agents, that take actions differently:
Type of Agent | Description |
---|---|
JSON Agent | The Action to take is specified as in JSON format |
Code Agent | The Agents writes a code bloc that is interpreted externally |
Function-calling Agent | It is a subcategory of the JSON Agent which has been fine-tuned to generate a new message for each action |
Actions themselves can serve many purposes:
Type of Action | Description |
---|---|
Information Gathering | Performing web searches, querying databases, or retrieving documents. |
Tool Usage | Making API calls, running calculations, and executing code. |
Environment Interaction | Manipulating digital interfaces or controlling physical devices. |
Communication | Engaging with users via chat or collaborating with other agents. |
One crucial part of an agent is the ability to STOP generating new tokens when an action is complete, and that is true for all formats of Agent; JSON, code, or function-calling. This prevents unintended output and ensures that the agent’s response is clear and precise.
The LLM only handles text, and uses it to describe the action it wants to take and the parameters to supply to the tool.
One key method for implementing actions is the stop and parse approach. This method ensures that the agent’s output is structured and predictable:
The agent outputs its intended action in a clear, predetermined format (JSON or code).
Once the action is complete, the agent stops generating additional tokens. This prevents extra or erroneous output.
An external parser reads the formatted action, determines which Tool to call, and extracts the required parameters.
For example, an agent needing to check the weather might output:
{
"thought": "I need to check the current weather for New York.",
"action": "get_weather",
"action_input": {
"location": "New York"
}
}
This clear, machine-readable format minimizes errors and enables external tools to accurately process the agent’s command.
Note: Function-calling agents operate similarly by structuring each action so that a designated function is invoked with the correct arguments. We’ll dive deeper into that type of Agents in a future Unit.
An alternative approach is using Code Agents. The idea is: instead of outputting a simple JSON object, a Code Agent generates an executable code block—typically in a high-level language like Python.
This approach offers several advantages:
For example, a Code Agent tasked with fetching the weather might generate the following Python snippet:
# Code Agent Example: Retrieve Weather Information
def get_weather(city):
import requests
api_url = f"https://api.weather.com/v1/location/{city}?apiKey=YOUR_API_KEY"
response = requests.get(api_url)
if response.status_code == 200:
data = response.json()
return data.get("weather", "No weather information available")
else:
return "Error: Unable to fetch weather data."
# Execute the function and prepare the final answer
result = get_weather("New York")
final_answer = f"The current weather in New York is: {result}"
print(final_answer)
In this example, the Code Agent:
This method also follows the stop and parse approach by clearly delimiting the code block and signaling when execution is complete (here, by printing the final_answer).
We learned that Actions bridge an agent’s internal reasoning and its real-world interactions by executing clear, structured tasks—whether through JSON, code, or function calls.
This deliberate execution ensures that each action is precise and ready for external processing via the stop and parse approach. In the next section, we will explore Observations to see how agents capture and integrate feedback from their environment.
After this, we will be finally ready to build our first Agent!
< > Update on GitHub