ARTICLE

Integrating AI Agent for Financial Tasks with LSEG Workspace

Zansong Zhu
Global Customer Technology Director Global Customer Technology Director
Raksina Samasiri
Developer Advocate Developer Advocate

Introduction

An AI agent refers to a computer program or system that utilizes artificial intelligence technologies e.g. Large Language Models (LLMs) to interact with users. It can sense surroundings, execute actions to complete complex task automatically and simulate human-like conversations to provide automated assistance to users in various aspects of domains. The combination of AI Agents and LLMs provides powerful capabilities for various application scenarios, enabling AI Agents to interact with humans in a more natural and intelligent manner.

Microsoft Autogen Studio is a cutting-edge tool that facilitates the rapid creation, management, and interaction with agents that possess the ability to learn, adapt, and collaborate. Autogen Studio streamlines the process of deploying multiple AI agents to work on complex tasks collectively. It is built on top of AutoGen, a framework that simplifies the creation of AI Agents, particularly useful for developing LLM applications using multiple agents that can talk with each other to achieve the same goal.

LSEG Workspace gives customer access to the broadest and deepest coverage of financial data, news, analytics, and productivity tools. With its integrated developer environment, you can also use and analyze data flexibly with modern APIs and popular languages like Python.

In this article, we will illustrate the process of constructing a Financial AI Agent using Microsoft Autogen Studio integrated with the LESG’s Data Library. This tutorial aims to assist financial professionals in retrieving, analyzing, and visualizing financial data efficiently in the new LLM world.

Disclaimer

The source presented here as well as the example code provided has been written by Refinitiv, an LSEG business for the only purpose of illustrating an article published on the Developer Community. They have not been tested for usage in production environments. Refinitiv cannot be held responsible for any issues that may happen if these objects or the related source code is used in production or any other customer's environment.

Prerequisites

Configuring AutoGen Studio for Financial Use Cases with LSEG Workspace

AutoGen Studio Installation and Initial Configuration

After completing the installation items in prerequisites,

  1. Run pip install autogenstudio
  2. Set Open AI API key in your environment, for example,
    1. if you are running a Linux or Mac environment, you can run command: export OPENAI_API_KEY=<your OpenAI key>
    2. For Windows, use the command: set OPENAI_API_KEY=<your OpenAI key>
  3. Running AugenStudio application: autogenstudio ui --port 8081
  4. Open “http://local host:8081” in your browser to access the studio.

AutoGen Studio Components For Defined Use Cases

The diagram presented below illustrates the essential components of AutoGen Studio and how it will interact with LSEG Workspace.

We will perform the following actions to execute various use cases in the subsequent sections. These use cases may include financial charting, bond pricing, and other related activities.

  1. Create an Agent named workspace_assistant powered by GPT-4.
  2. Create a Bond Pricing skill which contains a specialized function powered by the Instrument Pricing Analytics (IPA) in the Data Library for Python to price Govcorp and Muni Bond and add the skill into the workspace_assistant
  3. Create a new Workflow that includes workspace_assistant agent, a user proxy agent which will be responsible for managing and facilitating user conversations with the workspace_assistant agent, ensuring a smooth and efficient interaction between users and workspace_assistant agent supposed to be a financial domain expertise.

1) Create a new Bond Pricing Skill

In Autogen studio browser, navigate to 'Skills' sub menu, click New Skill to add bond pricing skill which is implemented by LSEG's Data Library with IPA API to price Govcorp/Muni bonds

2) Create a new workspace agent

Navigate to 'Agents' sub menu and click New Agent button to create a new Agent named workspace_assistant and add Bond Pricing skill to the new agent. The agent will use GPT-4 model by default.

3) Create a New Workflow

Navigate to 'Workflows' sub menu, click New Workflow button to create a new workflow named 'Workspace Agent Workflow' and select workspace_assistant agent as a Receiver and a userproxy agent as a Sender by default setting for direct user interaction.

4) Converse with workspace agent to complete financial tasks

Start Playground

After completing all the setup and configuration in AutoGen Studio, let’s go to Playground tab and click ‘New’ to create a new Workspace Agent Workflow session to start the real journey, suppose you must and should have logged into LSEG workspace on the same machine already as we're going to use the Desktop session of the Data Library (more detail can be found at: Data Library Quick Start guide and the Example code)

5) Let's work with the agent to retrieve and visualize the data

5.1) Plotting Historical Prices for CNY and CNH

In the playground GUI, enter your charting requirements to Agent. In foreign exchange markets, Chinese RMB has onshore (CNY) and offshore (CNH) market. We ask agent to plot both CNY/USD and CNH/USD on the same chart using your Workspace Desktop Session of the Data Library to retrieve the data from the Data Platform.

The agent will figure out everything needed by itself including installing all necessary Python packages to accomplish the task.

Here are the agent messages in the process, the automatically generated chart image, and the source code for 'plot_fx_prices.py.'

    	
            

# filename: plot_fx_prices.py

import eikon as ek

import matplotlib.pyplot as plt

import pandas as pd

 

# Set your Eikon API key here

ek.set_app_key('xxxxxx')

 

# Define the RICs for CNY and CNH

rics = ['CNY=', 'CNH=']

 

# Define the fields for the data request

fields = ['CLOSE']

 

# Define the date range for the year 2023

start_date = '2023-01-01'

end_date = '2023-12-31'

 

try:

    # Fetch the FX price data for CNY and CNH for 2023

    df_cny = ek.get_timeseries(rics[0], fields=fields, start_date=start_date, end_date=end_date)

    df_cnh = ek.get_timeseries(rics[1], fields=fields, start_date=start_date, end_date=end_date)

 

    # Plot the data

    plt.figure(figsize=(10, 5))

    plt.plot(df_cny.index, df_cny['CLOSE'], label='CNY')

    plt.plot(df_cnh.index, df_cnh['CLOSE'], label='CNH')

    plt.xlabel('Date')

    plt.ylabel('FX Price')

    plt.title('FX Price of CNY and CNH for 2023')

    plt.legend()

    plt.grid(True)

 

    # Save the plot to a file

    plt.savefig('ccp_cn.png')

    print("The chart has been saved to ccp_cn.png")

 

except Exception as e:

print(f"An error occurred: {e}")

5.2) Adding a new spread line to the chart

Tell agent to add a new spread line added to the chart to show historical price differences between CNY and CNH

5.3) Drawing Technical Analysis Charts of EUR

5.4) Financial Calculation – Bond Pricing

In this case, the Agent will call the bond pricing skill created at beginning of section to price a bond for a given CUSIP.

Summary

In this article, we demonstrate how to use an opensource AI Multi-Agent tool - AutoGen Studio to build a multiple Agent sample application to power LSEG workspace users.

Multi-agent offers a valuable approach to breaking down complex problems into manageable units of work and allocating specific tasks to agents with expertise in those areas for more focused and efficient problem-solving. By leveraging the capabilities of different agents and combining them with the power of Large Language Models (LLMs), multi-agent designs provide a structured framework for tackling intricate problems in a more tractable manner.  

In addition to Autogen Studio, other multi-agent frameworks and tools are emerging, such as LangGraph and CrewAI etc., these new platforms contribute to the ever-growing landscape of multi-agent systems, offering alternative options for developers and researchers to explore. With the continuous development of these frameworks, the field of multi-agent technology is expanding, fostering innovation, and enabling new possibilities in AI-driven applications.

While the examples provided may not cover many potential complexities, they illustrate the initial steps in leveraging multi-agents for financial tasks. The benefits of incorporating AI agents into the finance sector include:

  • Trust data source - LSEG Workspace: Financial professionals rely on accurate data for decision-making. The AI agent's effectiveness is directly tied to high quality data it receives from the Data Library, and avoid flawed analyses and potentially incorrect financial decisions caused by inaccurate data.
  • By utilizing the ‘Skills’ function in multi-agent frameworks, it enables seamless interaction between AI agents and professional financial models, as well as external APIs. This integration allows for sophisticated financial analysis, accurate calculations via powerful LSEG IPA financial calculation API. The multi-agent approach can also leverage the expertise of different agents, combining their strengths to deliver comprehensive and reliable financial insights that surpass the capabilities of a single LLM.
  • Increased Efficiency: AI agents excel at automating routine tasks such as data entry, analysis, and reporting. By handling these tasks, they enable financial professionals to allocate their time and expertise to more strategic and value-added activities.