How can we create an AI agent to run actions on documents?

Tabla de contenidos

Note: Agents currently require OpenAI as the AI engine.

Athento lets you create AI agents that run actions on documents. This lets you automate a series of actions on documents without doing them manually.

Creating the agent

To create an agent you must be a team administrator and go to the team’s "Agents" tab.

In this tab you can edit and delete existing agents or create a new one. When creating or editing an agent, fill in these fields:

  • Teams: the teams where this agent will be available.
  • Name: a distinctive name for the agent.
  • System prompt: the instructions you want the agent to carry out. The instructions must follow the order of the flow you want the agent to run. Example:
The document contains an email from a user. You must get that email to look up information about the
company and automatically fill in the metadata company_name, sector and country.

Now you must check whether it is a valid request. It is valid if you were able to fill in the metadata from the previous step.
If the request is valid, change the lifecycle state to "Handled".
If the request is not valid, change the lifecycle state to "Not a request".

If the state has moved to "Handled", ATHENTO will create a related document of type "X".
You must request this related document.

Once you have the document of type "X", you must assign to that document the company obtained at the beginning.
  • Tools: the tools the agent can use. Select the tools you want the agent to have available. If the instructions ask for an action but the agent does not have the tool for it, that action will not be run. Available tools:
    • Update document: updates a field or the document name.
    • Update the document’s lifecycle state.
    • Create document.
    • Run an automation.
    • Get related documents: lets the AI ask for a related document when it needs information about it.
    • Search documents: lets the agent search documents in the team of the document it runs on to gather information about them.
  • Execution user (can only be set from administration, and only by a superuser): the user used to run the agent. You need to set it when the agent will run in an automatic process, so that the agent’s access is limited to that user’s permissions. For example, if the agent uses the "Search documents" tool, this user limits which documents the agent can find.

Running the agent

To run the agent, enable the "op_run_agent" automation in the space. You will find it in the space’s automation library.

In this automation, select the agent you created earlier.

Once configured, you can run the agent on a specific document using the automation. After running it, a message tells you the agent has started. The agent runs in the background.

Viewing the agent execution

From the document history

In the document history, the Agents tab shows every agent execution on that document. The tab is only shown to users with administration permissions on the document.

The table shows one row per execution with these columns:

  • Agent: the agent that ran.
  • Status: execution status (Pending, Running, Success, Error or Cancelled).
  • Start Date and End Date: when the execution started and ended.
  • Details: + button to see the execution details.

From the table bar you can filter by agent name and refresh the list to see the latest status of an execution in progress.

Clicking + opens the execution details, with the agent’s final result (Result) and the list of actions it performed on the document, in the order it did them. For each action you see:

  • Action: the tool the agent used (update the document, change the state, create a document…).
  • Date: when it ran it.
  • Result: whether the action worked or failed.
  • Data: the data the agent used to perform it.

This way you can follow step by step the flow the agent followed and know what changed in the document and why.

One active execution per agent and document

The same agent cannot run twice at the same time on the same document. While an execution is pending or in progress, running the automation again shows the message «There is already an active execution for this agent and document» and no new execution starts.

From advanced administration

You can see the agent’s execution status and the actions it performs from advanced administration. Go to "Athenea > Agent executions". There you will see the list of executions over time.

If you open a specific execution, you can see the following information:

  • Agent: the agent that ran.
  • Document: the document the agent ran on.
  • Status: status of the agent’s execution on the document. The available statuses are:
    • Pending: initial status. The execution has not started yet.
    • Running: the execution is in progress.
    • Success: the execution finished successfully.
    • Error: an error occurred during the execution.
    • Cancelled: the execution was cancelled for some reason.
  • Output: the agent’s final output message after completing the execution.
  • Error: error produced during the execution. If the status is "error", a message with the error is shown here.
  • Start time of the execution.
  • End time of the execution.
  • Actions performed by the agent. For each action you see:
    • Tool run.
    • Input data the agent used to run the tool.
    • Output data from running the tool.
    • Success: whether it worked correctly.
    • Error: if it failed, a message with the reason.

Unblocking stuck executions

If an execution stays in Pending and does not move on, the agent cannot be run again on that document. To unblock it, in Athenea > Agent executions select the execution and apply the Mark selected executions as error action. The execution moves to Error and the agent can be run again.

With this, you have an agent in Athento automating all kinds of actions on your documents!