Writing Agent Pseudocode
Pseudocode Scenarios
The agent pseudocode is a list of numbered steps that provides a blueprint for how the conversation with the LLM will proceed. Each step in the pseudocode is converted into a message according to the Sirji messaging protocol by the LLM. These messages are well understood by the Sirji framework, resulting in a limited number of allowed message templates. Thus each step of the pseudocode must adhere to one of the allowed scenarios.
Here are the scenarios for writing pseudocode steps, along with example snippets demonstrating each scenario.
Interacting with the User
Ask a Question
Example:
Ask SIRJI_USER to provide {{Write the question here}}.
RAG Assistant
Create an Assistant
Only one RAG assistant can be created per Sirji run and will be reused throughout.
Example:
Create an assistant with the following instructions:
{{Write the instructions here}}
Sync Project Files
Example:
Sync project files with the assistant.
Query the Assistant
Example:
Infer from the assistant with the following query:
{{Write the query here}}
Project Folder Operations
Read Files
Example:
Using the project folder structure, determine the file paths for the following core codebase files and read them for the specified purposes:
- OpenAPI file: Understand the input parameter and response specifications for the API.
- Sequence diagram relevant to the Target API: Understand the logic to be implemented.
Create a File
Example:
Under the services folder in the project, create a service file for the API, following the conventions used in the inspiration service file.
Update a File
Example:
Change the version in setup.py to 3.0.0.
Agent Output Folder Operations
Read a File
Example:
Read the problem statement from the Agent Output Folder.
Create a File
Example:
Store the problem statement in the Agent Output Folder.
Invoking Other Agents
An agent can be invoked in a fresh session or an existing session.
Fresh Session
Example:
Invoke agent NODE_JS_CREATE_API_PLANNER to {{write the purpose of invocation here}}.
Existing Session
Example:
Invoke agent NODE_JS_CREATE_API_PLANNER in the existing session to {{write the purpose of invocation here}}.
Terminal Operations
Run a Command
Example:
Run `npm install`
Start a Server Process
Example:
Start the server using command: `npm start`
Miscellaneous
Write to Scratchpad
The scratchpad is a personal note-taking space for the agent.
Example:
Understand the code conventions followed in the existing code which you have read and store your understanding in the scratchpad.
Pseudocode Guidelines
Follow these guidelines when writing agent pseudocode:
- Structure Clearly: Have a clear structure for the pseudocode to improve understanding and ease of editing.
- Ask Questions Early: As much as possible, ask questions to SIRJI_USER at the beginning to prevent unnecessary messages in the conversation, which can reduce costs.
- Read Files Efficiently: Read multiple files in one go to minimize redundant file content being sent in API calls, leading to lower costs.
- Define Terms Clearly: Define terms clearly for easy reference later in the pseudocode. Use phrases like "Let's call this ..." to establish terminology.
- Break Large Problem into Small Steps: Proceed incrementally when writing pseudo code. This allows LLM to perform small tasks sequentially instead of one complex task in one go. It is best to break your problem into several small steps.
- Ensure Scenario Alignment: Ensure that each point in the agent pseudocode corresponds to one and only one of the pseudocode scenarios mentioned above.
- Use Scratchpad to Remember LLM's Understanding Wherever you want the LLM to remember its understanding of the step you should explicitly ask it to save it in the scratchpad.