Build your first agent

This tutorial illustrates how to create a simple agent that raises the message: Hello World! The current time is: <time>. It describes how to write the source code for this agent by completing these tasks:

  • Adding references to your Visual Studio project.
  • Inheriting from the agent base class.
  • Overriding the Execute() method with your business logic and performing other key development tasks.
  • Adding the compiled .dll files for the agent to Relativity and view the messages that the agent raises.

Before you begin

Complete the following tasks to before you begin implementing an agent:

  • Set up your development environment. This tutorial uses Visual Studio to illustrate development tasks.
  • Install the Relativity Visual Studio templates. For more information, see Visual Studio templates for Relativity.
  • Obtain access to an instance of Relativity used for development purposes. In Relativity, confirm that you have the appropriate system admin permissions. For more information, see Security and Permissions on the RelativityOne Documentation site.

Build an agent

Follow these steps to build a simple agent in Visual Studio:

  1. Open Visual Studio.
  2. Click File > New > Project.
  3. In the New Project dialog, expand Relativity and select Agent.
  4. Enter BasicSampleAgent in the Name field and click OK.
  5. New Project dialog

  6. To view the references in the project, right-click on References in the Solution Explorer. The references are added to the project as part of the template.
  7. References

  8. In the Solution Explorer, right-click on the Relativity Agent.cs file. This file displays the template code for an agent.
  9. Update the kCura.Agent.CustomAttributes.Name to Basic Sample Agent. The class attribute which determines the name of the agent displayed in Relativity.
  10. Attributes

    Review the additional features of this code:

    • The GUID attribute added above the class name in the code.
    • The class is derived from the AgentBase class.
  11. Override the Name property and enter Basic Sample Agent as the name that you want returned for the agent. Only the WinForm debugging tool uses this property to identify the agent.
  12. code for overriding Name property

  13. Update the time message in the Execute() method. You must override the Execute() method inherited from the base class. The current method raises the message: Hello World! The time is: <time>. In the Relativity UI, you set an interval that specifies when this method is called. See step 22.
  14. Execute() method

  15. On the Build tab for your project properties, ensure that you select Active (x64) in the Platform field. Relativity libraries require this setting.
  16. Build tab

  17. To compile your agent source code, click Build > Build Solution. After your agent assembly builds successfully, you can upload it to Relativity.

    Build Solution menu option

  18. Open the Relativity instance used for development.

    Note: You can create a new workspace or use an existing one when you deploy your agent.

  19. Search for the Resource Files tab at the instance level.
  20. Click New Resource File.
  21. In the Application field, click Select to choose Default as the application. This action links your agent assembly to the default application. In general, you link your assemblies to a custom application that you are developing.
  22. In the Resource File field, click Select File to choose the BasicSampleAgent.dll from the directory where you built the project. For more information, see Basic concepts for agents.
  23. Resource File Information