About this Course¶
What you will learn¶
- Core GenAI concepts: LLMs, embedding models, RAG, and agents.
- Hands-On with GenAI platforms: OpenAI, HuggingFace, Ollama, and Tavily.
- Practical document processing: Parse, chunk, and vectorize annual reports using LangChain and LlamaIndex to build a vector database.
- Develop agentic RAG system: Use LangGraph to explore graph fundamentals like states, routing, map-reduce, and tool calling to develop an agent capable of answering risk-related questions about DAX 40 companies.
- Blueprint for developing your own agents
What is Generative AI?¶
To understand Generative AI's place in the broader AI landscape, it's important to understand how different AI technologies relate to and build upon each other.
Generative AI is fundamentally based on deep learning methods, but it distinguishes itself by creating new content, such as language.
Image source: Illustration by the author
Artificial Intelligence (AI): The Broad Umbrella
AI is the overarching field that encompasses all technologies and systems designed to simulate human intelligence. This includes tasks like reasoning, problem-solving, learning, and decision-making.
Machine Learning (ML): The Foundation
Machine learning is a subset of AI that enables systems to learn from data and improve their performance over time without being explicitly programmed. ML algorithms identify patterns in data and use these patterns to make predictions or decisions.
Deep Learning (DL): The Engine Behind Generative AI
Deep learning is a specialized branch of ML that uses artificial neural networks inspired by the human brain. These networks are particularly effective at processing large amounts of unstructured data, such as images, text, and audio.
Natural Language Processing (NLP): A Key Application Area
NLP is a field within AI focused on enabling machines to "understand", "interpret", and generate human language. It powers applications like chatbots, translation tools, and sentiment analysis.
Generative AI (GenAI):
GenAI is a specialized and creative branch of AI that leverages deep learning to generate new content. While it shares foundational techniques with deep learning, its focus on creation sets it apart. It also overlaps with NLP in language-based applications, but its scope extends beyond language to include images, videos, and more. This makes generative AI a unique and transformative technology within the broader AI ecosystem.
Application of Generative AI in Risk Management¶
GenAI holds many promises and is identified by some practitioners as the fourth industrial revolution. In the following, there are images which help to narrow down the projected impact of GenAI and its importance in the field of Risk and Finance.
Generative AI could create additional value potential above what could be unlocked by traditional AI and analytics.
Image source: McKinsey
Generative AI use cases will have different impacts on business functions across industries with Risk and Legal being an important field in Banking.
Image source: McKinsey
Most impactful GenAI uses cases in Finance and Risk have been identified and comprise tasks such as forecasting and budget planning, reporting creation and policy review.
Image source: Gardner
A GenAI PoC: Risk Agent¶
In the remaining course, we will go through a step-by-step process of developing the Risk Agent. At its core the Risk Agent utilizes a Retrieval Augmented Generation (RAG) system to provide users with up-to-date information about the risks faced by DAX 40 companies, leveraging their annual reports.
Large Language Models (LLMs), are very large deep learning models that are pre-trained on vast amounts of data. They are highly flexible as a single model can perform completely different generative tasks such as answering questions, summarizing documents, translating languages and completing sentences.
Retrieval Augmented Generation (RAG) is a technique for improving the quality of LLM-generated responses by grounding the model on external sources of knowledge. Relevant external knowledge is retrieved from a knowledge base and used to augment the model's generation process. This approach can help mitigate the model's tendency to hallucinate or produce incorrect information, as it provides a more reliable source of context for the generation task.
Additionally, we will enhance this system with AI agents that can independently decide which reports to retrieve based on user queries, even searching the web when necessary.
In general terms, agents refer to artificial intelligence systems that can act with a higher degree of autonomy than traditional AI solutions. Designed to function independently, these systems can perform tasks and make decisions without continuous human intervention or the need of predefined, hard-coded guidance.
A RAG system enhances an LLM's knowledge with up-to-date domain information from a document base, while an agentic RAG system allows it to independently decide which information sources to retrieve.

Image source: Illustration by the author
Developing a Mulit-Document Risk Agent¶
Moving on, we will primarily work with LlamaIndex and LangChain which are both leading Python frameworks for building LLM-powered workflows.

Image source: Superwise
Build a document vector store¶
We begin by creating a vector store, a specialized database that manages information as mathematical vectors, which represent the meaning of different sections of companies' annual reports. This vector store is crucial for the RAG system as it enables the retrieval of relevant, domain-specific information that enhances user queries, allowing the chat system to provide accurate and up-to-date responses that the underlying language model alone may struggle to deliver.
In the first step, we load the HuggingFace access token into our project's environment to gain access to various open-source embedding models that convert annual reports into context-aware vector representations.
An embedding model is a mathematical framework that transforms data, such as words or phrases, into vector representations that capture their contextual meanings.
import os
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
# Access the API key
huggingface_api_key = os.getenv("HUGGINGFACE_API_KEY")
Parse documents¶
The original annual reports for all DAX 40 companies from 2023 can be found in data/raw/reports/
. They are the starting point to build our
vector store.
reports = os.listdir('data/raw/reports/')
print(*reports[:3], '...', *reports[-3:], sep=',\n')
adidas_2023.pdf, airbus_2023.pdf, allianz_2023.pdf, ..., volkswagen_2023.pdf, vonovia_2023.pdf, zalando_2023.pdf
To read the annual reports, we utilize SimpleDirectoryReader
, which efficiently loads and parses local files, automatically selecting the
appropriate reader based on file format, specifically for the .pdf format of the reports. We will begin with the 2023 annual report of Adidas and apply the
same generic preprocessing steps to the annual reports of all other DAX 40 companies at the end of this section.
from llama_index.core import SimpleDirectoryReader
documents = SimpleDirectoryReader(
input_files=['data/raw/reports/adidas_2023.pdf']).load_data()
print(f"In total {len(documents)} Document objects have been loaded.")
In total 321 Document objects have been loaded.
As you can see, SimpleDirectoryReader
returns a list of 321 Document
objects, with each element representing a single page from
the previously loaded annual report.
Next, we utilize the custom function display_document_with_image_side_by_side()
to visually compare the text parsed by
SimpleDirectoryReader
with the original document. This allows for an effective side-by-side evaluation of the extracted content.
from util import display_document_with_image_side_by_side
display_document_with_image_side_by_side(
document=documents[165],
image_path='img/annual_report.png'
)
1 2 3 4 5 T O O U R SHA REHO L D ERS GRO U P MAN A GEMEN T REP O RT – O U R CO MPA N Y GRO U P MAN A GEMEN T REP O RT – F I N A N CI AL REVI EW CO N SO L I DA T ED FI N AN CI A L ST A T EMEN T S A D D I T I ON A L I N FO RMA T I ON 166 A N N U A L R E P O R T 2 0 2 3 Risk and Opportunity Report In order to remain competitive and ensure sustainable success, adidas consciously takes risks and continuously explores and develops opportunities. Our risk and opportunity management principles and system provide the framework for our company to conduct business in a well-controlled environment. Risk and opportunity management principles The key objective of the risk and opportunity management is to support business success and protect the company as a going concern through an opportunity-focused but risk-aware decision-making framework. Our Enterprise Risk Management Policy outlines the principles, processes, tools, risk areas, key responsibilities, reporting requirements, and communication timelines within our company. Risk and opportunity management is a company-wide activity that utilizes key insights from the members of the Executive Board as well as from global and local business units and functions. We define risk as the potential occurrence of an external or internal event (or series of events) that may negatively impact our ability to achieve the company’s business objectives or financial goals. Opportunity is defined as the potential occurrence of an external or internal event (or series of events) that can positively impact the company’s ability to achieve its business objectives or financial goals. Risk and opportunity management system The Executive Board has overall responsibility for establishing a risk and opportunity management system that ensures comprehensive and consistent management of all relevant risks and opportunities. The Enterprise Risk Management department governs, operates, and develops the company’s risk and opportunity management system and is the owner of the centrally managed risk and opportunity management process on behalf of the Executive Board. The Supervisory Board is responsible for monitoring the effectiveness of the risk management system. These duties are undertaken by the Supervisory Board’s Audit Committee. Working independently of all other functions of the organization, the Internal Audit department provides objective assurance to the Executive Board and the Audit Committee regarding the adequacy and effectiveness of the company’s risk and opportunity management system on a regular basis. In addition, the Internal Audit department includes an assessment of the effectiveness of risk management processes and compliance with the company’s Enterprise Risk Management Policy as part of its regular auditing activities with selected adidas subsidiaries or functions each year. Our risk and opportunity management system is based on frameworks for enterprise risk management and internal controls developed and published by the Committee of Sponsoring Organizations of the Treadway Commission (COSO). Additionally, we have adapted our risk and opportunity management system to more appropriately reflect the structure as well as the culture of the company. This system focuses on the identification, evaluation, handling, systematic reporting, and monitoring of risks and opportunities. Furthermore, we use a quantitative concept for risk capacity and risk appetite. Risk capacity is a liquidity-based measure and represents the maximum level of risk adidas AG can take before being threatened with insolvency. Risk appetite refers to the maximum level of risk the company is willing to take and is linked to the company's liquidity targets.

When using the text_resource in the Risk Agent, we need to remove the repetitive header information from each page, as it complicates the
content, and we only want to focus on the pages that contain information about the companies' 'Risk and Opportunity.' Ultimately, we aim to merge all
relevant pages of an annual report into a single Document
object to ensure that paragraphs split across two pages are
processed together.
pre_process_dict = {
"adidas": {
"pages": range(165, 187, 1),
"string_to_remove": "1 2 3 4 5 \nT O O U R SHA REHO L D ERS GRO U P MAN A GEMEN T REP O RT – \nO U R CO MPA N Y \nGRO U P MAN A GEMEN T REP O RT – \nF I N A N CI AL REVI EW \nCO N SO L I DA T ED FI N AN CI A L \nST A T EMEN T S \nA D D I T I ON A L I N FO RMA T I ON \n \n\\d{1,3} \n \n \n A N N U A L R E P O R T 2 0 2 3",
}
}
import re
from llama_index.core import Document
pages = pre_process_dict["adidas"].get("pages")
string_to_remove = pre_process_dict["adidas"].get("string_to_remove")
overall_text = ""
for page in pages:
document = documents[page]
text = document.text
text = re.sub(string_to_remove, "", text)
overall_text = "\n".join([overall_text, text])
report = Document(
text=overall_text,
metadata={'company': "adidas", 'year': 2023})
Chunk documents¶
In RAG systems, chunking is the process of dividing a large document into smaller, manageable pieces or "chunks" for easier storage and processing. These chunks are indexed and utilized during the retrieval phase to supply relevant information to the LLM, enhancing its performance and contextual understanding.
Chunking is essential in RAG for several reasons:
- Efficient Retrieval: By dividing large documents into smaller chunks, the system can quickly identify and retrieve only the most relevant pieces of information, rather than processing an entire document.
- Improved Accuracy: Smaller chunks help preserve context and ensure that the retrieved information is more focused and relevant to the user's query. This reduces the risk of irrelevant or inaccurate responses.
- Token Limits: LLMs have a maximum number of tokens that they can process at one time when generating responses. This is referred to as the model's context window size. Chunking documents into smaller parts allows to respect this context window size.
We use the SentenceSplitter
class which splits the document into chunks with a preference for complete sentences.
from llama_index.core.node_parser import SentenceSplitter
splitter = SentenceSplitter(
chunk_size=256,
chunk_overlap=20)
chunks = splitter.get_nodes_from_documents([report])
len(chunks)
67
The annual report has been split into 67 chunks whereas each chunk has at most 256 tokens.
Vectorize chunks¶
Once the documents have been chunked into smaller subsets, the next step is to convert them into vector representations.
We utilize the sentence-transformer as the embedding model for vectorizing the chunks of the annual reports. The version we are using has a context window size of 256 tokens, which aligns with the token size of the chunks created earlier, and it is hosted on HuggingFace, where we leverage their free inference API.
from langchain_huggingface import HuggingFaceEndpointEmbeddings
embed_model = HuggingFaceEndpointEmbeddings(
model="sentence-transformers/all-MiniLM-L6-v2",
huggingfacehub_api_token=huggingface_api_key,
)
embedding = embed_model.embed_documents(texts=[chunks[0].text])
len(embedding[0])
384
The embedding model translates the text into a 1x384 vector.
Typically, embeddings are organized within an index optimized for similarity search, and we use Faiss, a library developed by Meta AI, for efficient similarity search and clustering of dense vectors, particularly suited for large datasets and high-dimensional vectors. During query time, Faiss retrieves the top k embeddings along with the corresponding text chunks, providing context information for the LLM to accurately respond to user queries.
We set up a IndexFlatL2
which means the index stores the full vectors (i.e. without compressing or clustering the index) and performs exhaustive
search using Euclidean distance (L2). We save the generated Faiss index in memory using InMemoryDocstore
.
import faiss
from langchain_community.docstore.in_memory import InMemoryDocstore
from langchain_community.vectorstores import FAISS
from util import convert_llama_to_langchain
index = faiss.IndexFlatL2(len(embed_model.embed_query("hello world")))
vector_store = FAISS(
embedding_function=embed_model,
index=index,
docstore=InMemoryDocstore(),
index_to_docstore_id={},
)
vector_store.add_documents(
documents=[convert_llama_to_langchain(chunk) for chunk in chunks])
We can now send a query to the vector store which retrieves the top k most relevant chunks from the index.
vector_store.search(
query="What is Adidas doing to mitigate climate change related risks?",
search_type="similarity",
k=3)
[Document(id='32b53e34-0210-4f2d-9c99-04fcb297a471', metadata={'company': 'adidas', 'year': 2023}, page_content='This framework applies to all adidas businesses \nworldwide and also sets our expectations of third-party business partners for managing personal\n \ninformation for or on behalf of adidas. Our Global Privacy Officer and the Global Privacy department drive \nthe operational establishment of the framework and monitoring capabilities to track and report its \nimplementation. During the implementation, they are continuously providing further implementation \nguidance and training. \nHazard risks \nAs climate change intensifies, the likelihood and intensity of natural disasters such as storms, floods, \ndroughts, pandemics, or heat waves increases, and so does adidas’ potential risk. In addition, our business \nactivities could be impacted by port congestions, strikes, riots, armed conflicts, or terrorist attacks. All of \nthe above could damage our offices, stores, or distribution centers or disrupt our operational processes \n(e.g., sourcing, logistics) leading to loss of sales, higher cost, and a decrease in profitability. \nTo manage and mitigate these risks, we continuously monitor potential threats and have implemented \nbusiness continuity plans including but not limited to fallback solutions for transportation, dynamic \ncapacity management of containers and carriers, and reallocation of production.'), Document(id='368ec3ab-2c55-4825-a5e8-c3f7b7e37a0d', metadata={'company': 'adidas', 'year': 2023}, page_content='To \nreduce supplier dependency, the company follows a strategy of diversification. In this context, adidas \nworks with a broad network of suppliers in different countries and, for the vast majority of its products, \ndoes not have a single-sourcing model. \nCompliance risks \nAs a globally operating company, adidas is subject to various laws and regulations. Non-compliance with \nsuch laws and regulations could lead to penalties and fines and cause reputational damage. For example, \nnon-compliance with laws and regulations concerning data protection and privacy, such as the EU General \nData Protection Regulation (GDPR), may result in substantial fines. In addition, publication of failure to \ncomply with data protection and privacy regulations could cause reputational damage and result in a loss \nof consumer trust in our brands. We also face the risk that members of top management as well as our \nemployees breach rules and standards that guide appropriate and responsible business behavior. This \nincludes the risks of fraud, financial misstatements or manipulation, anti-competitive business practices, \nbribery, corruption, discrimination, and harassment in the workplace.'), Document(id='0fd313a1-2089-4796-bafe-e3ec7ec724e6', metadata={'company': 'adidas', 'year': 2023}, page_content='Currency risks are a direct result of multi-\ncurrency cash flows within the company, in particular the mismatch of the currencies required for \nsourcing our products versus the denominations of our sales. Furthermore, translation impacts from the \nconversion of non-euro-denominated results into the company’s functional currency, the euro, might lead \nto a material negative impact on our company’s financial performance. In addition, substantial changes in \nthe regulatory environment such as trade restrictions (e.g., concerning the US and China, or the EU and \nChina), economic and political sanctions, regulations concerning product compliance, social aspects, \nhuman rights, environmental, and climate protection regulations could lead to potential sales shortfalls or \ncost increases. ► SEE NOTE 28 \nTo mitigate these macroeconomic, sociopolitical, and regulatory risks, adidas strives to balance sales \nacross key regions and also between developed and emerging markets. We continuously monitor the \nmacroeconomic, political, and regulatory landscape in all our key markets to anticipate potential problem \nareas, so that we can quickly adjust our business activities accordingly upon any change in conditions.')]
Now, we will apply the steps demonstrated above to the annual reports of all DAX 40 companies. This process will ensure that we efficiently extract and analyze the relevant information from each report.
from util import parse_document, chunk_document, vectorize_chunks, pre_process_dict, convert_llama_to_langchain
from tqdm.notebook import tqdm
import asyncio
import nest_asyncio
nest_asyncio.apply()
vector_store = None
for report in tqdm(reports):
company = report.split('_')[0]
year = int(report.split('_')[1].split('.')[0])
document = parse_document(
f'data/raw/reports/{report}',
pre_process_dict.get(company),
company=company,
year=year)
chunks = chunk_document(document, chunk_size=256, chunk_overlap=20)
chunks = [convert_llama_to_langchain(chunk) for chunk in chunks]
# Check if vector_store exists; if not, create it
if vector_store is None:
vector_store = asyncio.run(vectorize_chunks(chunks, inference_api=False))
tqdm.write(f"Vector store created for {company} {year}.")
else:
# Add documents to the vector store
await vector_store.aadd_documents(chunks)
tqdm.write(f"Vector store updated for {company} {year}.")
With the filter argument we can now reduce the search to a specific DAX 40 company or alternatively query the entire vector store without setting any metadata filter.
# First filter by company, then conduct similarity search
vector_store._similarity_search_with_relevance_scores(
query="climate related risk",
filter={"company": "bmw"},
search_type="similarity_score_threshold",
k=3)
# Similarity search on the entire vector store
vector_store._similarity_search_with_relevance_scores(
query="climate related risk",
search_type="similarity_score_threshold",
k=3)
We have now developed the core element of the RAG part of our Risk Agent, i.e. the vector store holding context-aware vectors of the DAX 40 companies' annual reports.
In the next section, we make use of the vector store by integrating it into an agentic workflow which is capable to decide whether to query the vector store or search on the web to provide a meaningful answer to any user query.
Extend to a graph-based agent¶
A graph-based agent is a type of AI system that uses a structured graph to decide how to handle user queries. Think of the graph as a flowchart that connects different tools or actions the agent can take. Each node in the graph represents a specific tool or function (like searching a vector store or retrieving information from the web), and the edges between nodes define how the agent decides which tool to use based on the user's question.
For example, if a user asks, "What risks are DAX 40 companies facing related to cybersecurity?", the graph-based agent will analyze the query and decide:
- Should it search the vector store, i.e. the annual reports, for relevant information?
- Or should it search the web for the latest cybersecurity risks if the vector store doesn't have enough context?
The graph helps the agent orchestrate (or organize) the query and send it to the "right" tool to get the best answer.
We use LangGraph, a framework that helps you building graph-based agents. It allows you to define the structure of the graph and specify how the agent should behave when it receives a query.
Image source: Langchain AI
LangGraph makes it easier to:
- Connect Tools: You can connect your vector store, web search, or any other tools you want the agent to use.
- Define Logic: You can define rules or logic for how the agent decides which tool to use. For example, if the query is about risks of a specific DAX 40 mentioned in annual reports, the agent should prioritize the vector store. If the query is about recent risks not covered in the reports, it should search the web.
First, we load the required API keys:
- HuggingFace for vectorizing the user query,
- Tavily as web search tool,
- and optionally OpenAI if you want to use a GPT model as LLM.
If you do not want to use OpenAI's pay-as-you-go LLMs, the default will be Meta's open source and free of charge model Llama 3.1. Note however, that you need to have installed Ollama on your local machine to work with the free Llama models (see Prerequisites).
import os
from dotenv import load_dotenv
# Load environment variables from .env file
# load_dotenv()
# Access the API keys
huggingface_api_key = os.getenv("HUGGINGFACE_API_KEY")
tavily_api_key = os.getenv("TAVILY_API_KEY")
# Optional, if you want to experiment with OpenAI models
openai_api_key = os.getenv("OPENAI_API_KEY", None)
Next, we instantiate the LLM model via the custom function get_llm_model
.
# LLM
from util import get_llm_model
llm = get_llm_model(llm_type="ollama", model_name="llama3.1:8b") # If you want to experiment with OpenAI models change llm_type to "openai" and model_name to "gpt-4o-mini", for example.
llama3.1:8b model loaded.
We can then invoke the LLM directly by sending a query to it. Note that the answer generated in this way is based on the LLMs knowledge gained during training. There is no additional context provided to the LLM which makes it likely that the generated answer contains hallucinations.
answer = llm.invoke(
input="""What is the impact of climate change on the
business model of Adidas?""")
print(answer.content)
The impact of climate change on the business model of Adidas, like many other companies, is multifaceted and can be analyzed through several key areas: 1. **Supply Chain Vulnerabilities**: Climate change can disrupt supply chains due to extreme weather events, such as floods, droughts, and hurricanes. For Adidas, this could mean delays in production, increased costs, and challenges in sourcing materials. The company may need to diversify its supply chain or invest in more resilient logistics to mitigate these risks. 2. **Sustainable Materials and Production**: As consumers become more environmentally conscious, there is increasing demand for sustainable products. Adidas has already begun to incorporate recycled materials and sustainable practices into its production processes. Climate change pressures may accelerate this shift, pushing the company to innovate further in sustainable materials, such as bio-based plastics and organic cotton. 3. **Regulatory Changes**: Governments worldwide are implementing stricter regulations to combat climate change, which can affect manufacturing processes, emissions standards, and waste management. Adidas may need to invest in compliance and adapt its business practices to meet these regulations, potentially increasing operational costs. 4. **Consumer Preferences**: As awareness of climate change grows, consumers are increasingly favoring brands that demonstrate environmental responsibility. Adidas may need to enhance its marketing strategies to highlight its sustainability efforts and ensure that its products align with consumer values, which could influence pricing and product development. 5. **Brand Reputation and Risk Management**: Climate change poses reputational risks for brands that are perceived as not taking action. Adidas may need to proactively communicate its sustainability initiatives and engage in corporate social responsibility efforts to maintain a positive brand image and customer loyalty. 6. **Innovation and Product Development**: Climate change can drive innovation in product design and technology. Adidas may invest in research and development to create more sustainable products, such as shoes made from ocean plastic or biodegradable materials. This could open new market opportunities and differentiate the brand in a competitive landscape. 7. **Financial Implications**: The financial impact of climate change can manifest through increased costs related to raw materials, energy, and compliance. Adidas may need to reassess its pricing strategies and financial planning to account for these potential increases. 8. **Collaboration and Partnerships**: To address climate change effectively, Adidas may seek partnerships with NGOs, governments, and other businesses to share knowledge, resources, and best practices. Collaborative efforts can enhance the company's sustainability initiatives and amplify its impact. In summary, climate change presents both challenges and opportunities for Adidas. The company will need to adapt its business model to address these impacts, focusing on sustainability, innovation, and resilience to remain competitive in a changing market.
Next, we instantiate a Tavily object which will be used to retrieve relevant context from the web.
# Web search tool
from langchain_community.tools.tavily_search import TavilySearchResults
tavily_search = TavilySearchResults(max_results=2)
Similar to invoking the LLM, one can invoke the tavily_search
object and retrieve sources from the web that are relevant to the query.
web_context = tavily_search.invoke(
input="""What is the impact of climate change on the
business model of Adidas?""")
print(f"""Source: {web_context[1]['url']}
---
Content: {web_context[1]['content'][58:1000]} ...""")
Source: https://www.adidas-group.com/en/sustainability/planet/climate-change-and-decarbonization --- Content: sports brand, we acknowledge our role and are committed to reducing our environmental impact. We are adapting our business, reducing our own operations footprint and driving innovation - all with the ambition to mitigate our impact on the climate. ...
Before we build the graph, we need to introduce the concepts of state and state schema which are fundamental to how the system operates.
You can think of the state of a graph as the "data carrier" of the graph at that holds all the necessary information (e.g., user query, extracted topics, identified companies, retrieved relevant documents, and final response) as the system transitions from one node to another. The state evolves as the system progresses through the workflow, with each node potentially modifying or adding to the state.
The state schema, on the other hand, defines the structure of the state, including the types of nodes and edges, their properties, and how they relate to each other.
We use Pydantic
to define the following three classes Topic
, Company
, and Companies
which will determine
the state schema of our graph.
from typing import Optional, List
from pydantic import BaseModel, Field
class Topic(BaseModel):
dax_40_related: bool = Field(
description="Whether the query is related to DAX 40 companies.")
topic: str = Field(description="Topic of the query.")
class Company(BaseModel):
name: str = Field(description="Name of DAX 40 company.")
class Companies(BaseModel):
companies: Optional[List[Company]] = Field(
description="List of DAX 40 companies.")
There are two advantages of working with Pydantic
- Data Validation and Type Safety
Pydantic enforces strict type checking, ensuring that data conforms to expected structures and preventing runtime errors. For example, theTopic
class verifies that the LLM's output includes a boolean and a string with the correct types, while theCompanies
class checks that the list of companies is eitherNone
or a valid list ofCompany
objects.
- Structured Communication Between Agents
Pydantic ensures consistent and interpretable data exchange. The Topic class organizes outputs from the topic extraction agent for downstream processing, while the Companies class structures the output from the company extraction agent, ensuring that the RAG agent receives a well-defined list of companies to query. This structured approach enhances the reliability of the RAG system.
We then define two state classes OverallState
which inherits from MessageState
. This state class is shared across all nodes in the
graph.
import operator
from typing import Annotated, TypedDict
from langgraph.graph import MessagesState
class OverallState(MessagesState):
topic: Topic # topic of the user query including a boolean flag if it is related to DAX 40 companies and the description of the topic (see above)
companies: Companies # list of DAX 40 companies that are mentioned in the user query
context: Annotated[List[str], operator.add] # list of contextual information for each company retrieved from the vector store or the web
context_amount: Annotated[List[int], operator.add] # list of context retrieved for each company (number of documents)
context_count: int # overall number of context information retrieved across all companies
final_answer: str # final answer to the user query generated by the LLM
The second state class AnnualReportState
is hidden. It stores data that is required only for the RAG part in the system and does not need to
be shared globally across the graph.
class AnnualReportState(TypedDict):
company: Company # Company for which the context is retrieved from its annual report
context_report: Annotated[List[str], operator.add] # Context retrieved from the annual report
The operator.add
function serves as a state reducer, which updates the graph state by appending new information to the
existing data. In contrast, the default reducer simply replaces the existing information with the new input, such as when a newly generated topic overwrites
the previous one.
Extract topic¶
In the first node of your agentic system, extract_topic_node
, we use the LLM to identify the topic of the user query and
check if it is related to DAX 40 companies. If the query is not related to DAX 40 companies, we route the system to a standardized off-topic response,
off_topic_response_node
. If the question is related to DAX 40 companies we route the system to the next node where we use the
LLM to identify the companies mentioned in the user query. The routing logic is defined in the general_router
function.
Define system prompt instructing the LLM to extract topic from the query if the query is DAX 40 related.
topic_extraction_instruction = """You are part of an AI agent
designed to answer questions about the risks DAX 40 companies
are facing.
Your task is to judge whether the following user query is a
question concerned about DAX 40 companies or not.
Note that the user query may not explicitly mention any DAX 40 companies,
but it may still be related to them. If it mentions any DAX 40 companies,
it is for sure a DAX 40 related question.
Questions that refer to any type of risks that corporations
could face should be flagged as DAX 40 related.
If the user query is related to DAX 40 companies, you should
extract the topic of the question. If the user query is not
related to DAX 40 companies, please return nothing.
The topic should be a short phrase that summarizes the main subject
of the question. Please make sure to retain specific keywords that
are relevant to the topic.
This is the user query from which you should extract the topic: {message}.
Company names or the term 'DAX 40' should not be included in the topic.
"""
Define node which extracts topic.
from langchain_core.messages import HumanMessage, SystemMessage
def extract_topic_node(state: OverallState):
messages = state.get('messages')
last_message = messages[-1].content
# Enforce structured output
structured_llm = llm.with_structured_output(Topic)
# Create a system message
system_message = topic_extraction_instruction.format(message=last_message)
# Extract topic
topic = structured_llm.invoke(
[SystemMessage(content=system_message)]+
[HumanMessage(
content="""Please judge if the user query is related to
DAX 40 companies or not.
If it is, please extract the topic of the query.""")])
return {'topic': topic}
Define router to route to next node:
extract_companies_node
if query is on topicoff_topic_response_node
if query is off topic
def general_router(state: OverallState):
topic = state.get('topic')
dax_40_related = topic.dax_40_related
# Check if the query is related to DAX 40 companies
if dax_40_related:
return "on-topic"
else:
return "off-topic"
def off_topic_response_node(state: OverallState):
final_answer = """Your query is not concerned about DAX 40 companies
and therefore off topic within the context of this agent."""
return {"final_answer": final_answer}
Extract companies¶
The next step in our system, extract_companies_node
, extracts the concrete companies mentioned in the user
query and maps them against a list of harmonized company names defined in the following dax_40
list.
dax_40 = ['adidas', 'airbus', 'allianz', 'basf', 'bayer', 'beiersdorf',
'bmw', 'brenntag', 'commerzbank', 'continental', 'daimler-truck',
'deutsche-bank', 'deutsche-börse', 'deutsche-post',
'deutsche telekom', 'eon', 'fresenius', 'fresenius-medical-care',
'hannover-rück', 'heidelberg-materials', 'henkel',
'infineon-technologies', 'mercedes-benz', 'merck', 'mtu',
'münchener-rück', 'porsche', 'qiagen', 'rheinmetall', 'rwe',
'sap', 'sartorius', 'siemens', 'siemens-energy',
'siemens-healthineers', 'symrise', 'volkswagen', 'vonovia',
'zalando']
If the user query does not mention any specific DAX 40 company, the system will answer the query for all DAX 40 companies.
This logic is defined in the rag_router
which sends extracted companies/all DAX 40 companies to the vector store from which relevant context is
retrieved.
It is noteworthy that routing the extracted companies to the vector store is a map-reduce operation which means that the company names are
not send to the vector store sequentially but in parallel. This becomes possible with langraph's Send
API.
Instruct the LLM to identify and extract any company names from the query.
company_extraction_instruction = """You are tasked with analyzing whether the following
user query relates to any specific DAX 40 companies: {message}.
If you find specific DAX 40 companies mentioned in the user query,
map them to the ones mentioned in the following list: {dax_40}.
It may well be that the user query is a more generic question
that is not related to any specific company.
"""
Define node wich extracts the company names.
def extract_companies_node(state: OverallState, dax_40: list = dax_40):
messages = state.get('messages')
last_message = messages[-1].content
dax_40 = ', '.join(dax_40)
structured_llm = llm.with_structured_output(Companies)
system_message = company_extraction_instruction.format(
message=last_message, dax_40=dax_40)
companies = structured_llm.invoke(
[SystemMessage(content=system_message)]+
[HumanMessage(
content="""Extract the set of DAX 40 companies
if there are mentioned any. Otherwise return nothing.""")])
return {'companies': companies.companies}
Route extracted companies to the rag_agent_node
in parallel.
from langgraph.types import Send
def rag_router(state: OverallState, dax_40: list = dax_40):
companies = state.get('companies', None)
topic = state.get('topic')
# Check if any companies were extracted
if companies is not None:
return [Send(
"rag_agent",
{"company": c, "topic": topic.topic}) for c in companies]
else:
return [Send(
"rag_agent",
{"company": Company(name=c), "topic": topic.topic}) for c in dax_40]
Retrieve context¶
The next step is the core component in our agentic RAG system. For each extracted company the rag_agent_node
is triggered which searches the vector store for relevant context chunks which help to answer the user query. The similarity search is
conducted for each company in parallel with a metadata filter on the respective company name.
If no relevant context for the companies is found, the query is sent to the web_agent_node
through the
web_router
to search the web for pertinent information. This web search serves as a fallback when annual company reports do
not provide sufficient context.
Instruct LLM to generate a response based on the context retrieved for specific company.
single_answer_generation_instruction = """Based on the following context for
{company}, generate an answer to the topic '{topic}': \n\n {context}.
If the context does not provide enough information, please answer that
the annual report of {company} does not provide any information
about the topic '{topic}'.
"""
Define node which retrieves company-specific context from vector store.
import numpy as np
def rag_agent_node(
state: AnnualReportState,
vector_store: FAISS = vector_store):
company = state.get('company')
topic = state.get('topic')
context_report = vector_store.similarity_search(
query=topic,
k=2,
filter={"company": company.name})
context_amount = len(context_report)
if context_amount == 0:
answer = f"""The annual report of {company.name} does not provide any
information about the topic '{topic}'."""
else:
system_message = single_answer_generation_instruction.format(
company=company.name,
topic=topic,
context='\n\n---\n\n'.join(
[node.page_content for node in context_report]))
answer = llm.invoke(system_message).content
return {"context_report": context_report, "context": [answer],
"context_amount": [context_amount]}
Count the number of context chunks retrieved from the vector store across all companies.
If no context chunks were retrieved route to web_agent_node
.
def count_context_node(state: OverallState):
context_amount = state.get('context_amount')
state['context_count'] = np.sum(context_amount)
return {"context_count": state['context_count']}
def web_router(state: OverallState):
context_count = state.get('context_count')
if context_count == 0:
return "relevant-context-not-found"
else:
return "relevant-context-found"
Define node that retrieves context from web.
def web_agent_node(state: OverallState):
messages = state.get('messages')
last_message = messages[-1].content
search_docs = tavily_search.invoke(last_message)
formatted_search_docs = "\n\n---\n\n".join(
[
f'<Document href="{doc["url"]}">\n{doc["content"]}\n</Document>'
for doc in search_docs
]
)
return {"context": [formatted_search_docs]}
Generate answer¶
The final step of the Risk Agent utilizes context from annual reports or web sources to generate a comprehensive answer to the user query across all companies, which is then presented to the user.
Instruct LLM to generate an overall response.
final_answer_generation_instruction = """You are tasked to provide a concise
answer to the following query: {message}.
To respond to the user, you are supposed to use the following contextual
information: {context}.
If you find that the context contains repetitive information, please
summarize it accordingly.
If the context mentions DAX 40 companies, please make sure to explicitly
include them in your answer.
"""
Define the node which generates the final answer by reducing the company-specific information to a single string.
def generate_answer_node(state: OverallState):
messages = state.get('messages')
last_message = messages[-1].content
context = state.get('context', None)
system_message = final_answer_generation_instruction.format(
message=last_message,
context='\n\n---\n\n'.join(context))
final_answer = llm.invoke(system_message).content
# Return the company-specific answer
return {"final_answer": final_answer}
Build the graph¶
Finally, we build the graph and add all nodes and edges defined above.
from langgraph.graph import START, END, StateGraph
builder = StateGraph(OverallState)
builder.add_node("extract_topic", extract_topic_node)
builder.add_node("off_topic_response", off_topic_response_node)
builder.add_node("extract_companies", extract_companies_node)
builder.add_node("rag_agent", rag_agent_node)
builder.add_node("count_context", count_context_node)
builder.add_node("web_agent", web_agent_node)
builder.add_node("generate_answer", generate_answer_node)
builder.add_edge(START, "extract_topic")
builder.add_conditional_edges("extract_topic", general_router, {
"on-topic": "extract_companies", "off-topic": "off_topic_response"})
builder.add_conditional_edges("extract_companies", rag_router, {
"map-reduce": "rag_agent"})
builder.add_edge("rag_agent", "count_context")
builder.add_conditional_edges("count_context", web_router, {
"relevant-context-found": "generate_answer",
"relevant-context-not-found": "web_agent"})
builder.add_edge("web_agent", "generate_answer")
builder.add_edge("generate_answer", END)
builder.add_edge("off_topic_response", END)
graph = builder.compile()
Displaying the graph gives you a visual representation of the flow of the agent.
from IPython.display import Image, display
display(Image(graph.get_graph(xray=1).draw_mermaid_png(
frontmatter_config={
"config": {
"layout": "dagre",
"look": "handDrawn"}}
)))
We can now stream the graph to propagate the user query through the graph-based agent in oder to generate a final answer.
from util import print_graph_propagation
# Off-topic query
query = "How is the weather in New York?"
print_graph_propagation(graph, query)
User query: How is the weather in New York? ----------------- Graph events: {'extract_topic': {'topic': Topic(dax_40_related=False, topic='')}} {'off_topic_response': {'final_answer': 'Your query is not concerned about DAX 40 companies and therefore off topic within the context of this agent.'}} ----------------- Answer: Your query is not concerned about DAX 40 companies and therefore off topic within the context of this agent.
# Query with specific DAX 40 companies
query = "What are the climate-related risks for Adidas and BMW?"
print_graph_propagation(graph, query)
User query: What are the climate-related risks for Adidas and BMW? ----------------- Graph events: {'extract_topic': {'topic': Topic(dax_40_related=True, topic='climate-related risks')}} {'extract_companies': {'companies': [Company(name='adidas'), Company(name='bmw')]}} {'rag_agent': {'context_report': [Document(id='07512924-8d4b-40ef-b846-9dfa66092443', metadata={'company': 'adidas', 'year': 2023}, page_content='Climate scenario analysis confirmed our previous findings that the overall global greenhouse gas emission \nlevels will be an important factor influencing the magnitude of risks and opportunities. Moreover, these \nrisks and opportunities will gain relevance for our business, especially in the medium to long term. \nWe have categorized climate-related risks and opportunities following the ‘Task Force on Climate-Related \nFinancial Disclosures’ (‘TCFD’) framework. Given the different time horizons and complexity of climate-\nrelated risks and opportunities, the overview is presented separately from the illustration of risks and \nopportunities in this Risk and Opportunity Report.\u202fWe do not expect this to result in any additional major \nrisks and opportunities for the forecast for the 2024 fiscal year compared to the explanations given in the \nRisk and Opportunity Report. \nPhysical risks \n─ Physical damage and business disruption in our own or our business partners’ properties: Extreme \nweather events and changes in the overall weather patterns could increasingly lead to damages to \nowned or business partners’ properties (such as office buildings, distribution centers, and retail \nstores) and inventories, as well as business disruptions.')], 'context': ['The annual report of adidas provides information about climate-related risks, specifically highlighting the physical risks associated with extreme weather events and changes in overall weather patterns. These risks include potential damage to owned or business partners’ properties, such as office buildings, distribution centers, and retail stores, as well as disruptions to business operations. The report emphasizes that these climate-related risks and opportunities will become increasingly relevant for the business, particularly in the medium to long term, and categorizes them according to the TCFD framework. However, it notes that no major additional risks or opportunities are expected for the forecast of the 2024 fiscal year compared to previous assessments.'], 'context_amount': [1]}} {'rag_agent': {'context_report': [Document(id='98eaf969-33dd-4ac8-b975-662454b3b3ca', metadata={'company': 'bmw', 'year': 2023}, page_content='Moreover, oth er \noverarching topics are monitored by means of regular media \nanalysis. Any material reputational repercussions are described \nin the section ↗ Material Short-Term Risks and Opportunities. \nClimate-related risks \nRisks associated with climate change are presented in the sec-\ntion ↗ Climate-Related Risks and Opportunities. Climate-related risks are \nevaluated as physical and transitory risks in accordance with the \nrecommendations of the Task Force on Climate-related Finan-\ncial Disclosures (TCFD). Transitory risks arise from the transition \nto a low-carbon economy and are evaluated with the help of cli-\nmate-related risk drivers and qualitative expert assessments. \nPhysical risks arise due to climate change and are evaluated us-\ning external data on potential natural hazards. Potential short -\nterm impacts of climate change are already included in the short-\nterm risks. All short-term risks are evaluated for their climate im-\npact. If a risk is categorised as climate -relevant, the climate-re-\nlated portion of the risk is determined.'), Document(id='56e22e0b-e192-42c8-a91d-b8dcb1ce3ad9', metadata={'company': 'bmw', 'year': 2023}, page_content='Regulatory re-\nquirements introduced at short notice may enter into force, which \ncould have an impact on products, production and supply chains. \nIn the “Market and competition” risk dimension, risks may also \nincrease due to higher demand and the resulting higher prices for \nselect (scarce) raw materials on the one hand and due to rising \nenergy prices on the other. \nTransitory climate risks \n \nPhysical climate risks \nIn addition to the transitory risks, the BMW Group also evaluates \nphysical risks. In doing so, the increasing frequency and intensity \nof acute extreme weather events, such as heatwaves, storms \nand floods, are taken into account, along with longer-term \nchanges such as in terms of temperature and rainfall. \nIn order to measure such risks, we draw on external data that \nevaluate the development of acute and persistent natural phe-\nnomena across the global warming scenarios and across time. \nFor the BMW Group, this may result in damage to assets such as \nbuildings, vehicles or parts on the one hand, and on the other \nhand, such events may lead to downtime at BMW Group sites or \nat suppliers’ sites.')], 'context': ['The annual report of BMW provides a comprehensive overview of climate-related risks, categorizing them into transitory and physical risks in line with the recommendations of the Task Force on Climate-related Financial Disclosures (TCFD). Transitory risks are associated with the transition to a low-carbon economy and are assessed through climate-related risk drivers and expert evaluations. These risks may arise from sudden regulatory changes that could impact products, production, and supply chains, as well as from increased demand and rising prices for scarce raw materials and energy.\n\nOn the other hand, physical climate risks are evaluated based on the increasing frequency and intensity of extreme weather events, such as heatwaves, storms, and floods, as well as long-term changes in temperature and rainfall patterns. The BMW Group utilizes external data to assess these risks, which could lead to damage to assets and potential downtime at both BMW Group and supplier sites. Overall, the report highlights the importance of understanding and managing these climate-related risks to ensure the resilience and sustainability of the company.'], 'context_amount': [2]}} {'count_context': {'context_count': np.int64(3)}} {'generate_answer': {'final_answer': 'Adidas faces climate-related risks primarily from physical threats associated with extreme weather events and changing weather patterns. These risks could damage properties like office buildings and distribution centers, disrupt business operations, and are expected to become more significant in the medium to long term. However, no major new risks are anticipated for the 2024 fiscal year.\n\nBMW categorizes its climate-related risks into transitory and physical risks. Transitory risks stem from the transition to a low-carbon economy, including regulatory changes affecting products and supply chains, as well as rising costs for raw materials and energy. Physical risks involve the increasing frequency of extreme weather events and long-term climate changes, which could damage assets and disrupt operations at both BMW and its suppliers. The company emphasizes the need to manage these risks for resilience and sustainability. \n\nBoth companies are part of the DAX 40 index, highlighting their significance in the German economy.'}} ----------------- Answer: Adidas faces climate-related risks primarily from physical threats associated with extreme weather events and changing weather patterns. These risks could damage properties like office buildings and distribution centers, disrupt business operations, and are expected to become more significant in the medium to long term. However, no major new risks are anticipated for the 2024 fiscal year. BMW categorizes its climate-related risks into transitory and physical risks. Transitory risks stem from the transition to a low-carbon economy, including regulatory changes affecting products and supply chains, as well as rising costs for raw materials and energy. Physical risks involve the increasing frequency of extreme weather events and long-term climate changes, which could damage assets and disrupt operations at both BMW and its suppliers. The company emphasizes the need to manage these risks for resilience and sustainability. Both companies are part of the DAX 40 index, highlighting their significance in the German economy.
# DAX 40 related query but without mentioning any specific company
query = "Which risks do corporations face due to climate change?"
print_graph_propagation(graph, query)
User query: Which risks do corporations face due to climate change? ----------------- Graph events: {'extract_topic': {'topic': Topic(dax_40_related=True, topic='risks corporations face due to climate change')}} {'extract_companies': {'companies': None}} {'rag_agent': {'context_report': [], 'context': ["The annual report of adidas does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of allianz does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of basf does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of bayer does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of beiersdorf does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of bmw does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of commerzbank does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of continental does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of daimler-truck does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of deutsche-bank does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of deutsche-börse does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of deutsche-post does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of deutsche telekom does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of fresenius does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of fresenius-medical-care does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of hannover-rück does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of infineon-technologies does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of mercedes-benz does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of merck does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of mtu does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of münchener-rück does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of porsche does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of rwe does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of sap does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of siemens does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of sartorius does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of siemens-healthineers does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of symrise does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of volkswagen does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [], 'context': ["The annual report of zalando does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [0]}} {'rag_agent': {'context_report': [Document(id='0539a183-d04a-493c-94d9-665f873afd26', metadata={'company': 'brenntag', 'year': 2023}, page_content='87\nNfR, p. 108\n133\nAnnual Report 2023 Brenntag SE\nAPPENDIX\nTO OUR \nSHAREHOLDERS\nREMUNERATION \nREPORT\nMANAGEMENT \nREPORT\nCONSOLIDATED \nFINANCIAL STATEMENTS\nFURTHER \nINFORMATION\nNON-FINANCIAL \nREPORT\nRisk Management\nTCFD core element Required information\nReference to CDP\nClimate Change 2023 \nQuestionnaire\nDisclosure of processes for \nidentifying, assessing, and managing \nclimate-related risks\na) Processes for identifying and assessing climate-related \nrisks\nC2.1\nC2.2\nC2.2a\nb) Processes for managing climate-related risks C2.1\nC2.2\nc) Integration of processes for identifying, assessing, \nand managing climate-related risks into overall \nrisk management\nC2.1\nC2.2\nYou can find further information here: NfR, p. 108\nManagement Report, p.')], 'context': ["The annual report of Brenntag does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [1]}} {'rag_agent': {'context_report': [Document(id='eced9aab-f5ec-401d-957e-6ffb3b4cd26f', metadata={'company': 'eon', 'year': 2023}, page_content='Risk \nand sustainability managers at the units were actively involved in \nthis process. The status of this process is presented to the E.ON \nGroup Risk Committee on a regular basis. Our analyses of climate \nrisks encompass physical risks (such as extreme weather and \nrising temperatures) as well as transitional risks (such as changes \nin consumer preferences, the regulatory environment, and carbon \npricing). The Risks and Chances Report contains additional \ninformation. \nMetrics and Targets \nE.ON’s current climate metrics consist mainly of the emission \nfigures for its carbon footprint categories (Scope 1, 2, and 3) and \nthe measurement of progress toward its climate targets (see \nabove). The climate targets defined in 2020 remain valid (see \nClimate Protection chapter). We monitor progress toward these \ntargets on an annual basis for all relevant GHG categories. The \naforementioned carbon management plan apportions our \nemission-reduction targets to the business units, while giving \nthem the operational decision-making authority on how to achieve \nthem. \nIn addition, E.ON discloses avoided emissions.'), Document(id='27aa5ea6-ae48-4798-b23a-6e2b11622dee', metadata={'company': 'eon', 'year': 2023}, page_content='At year-end 2023, E.ON had not identified any major risks related \nto its own business activities and business relationships as well as \nproducts and services pursuant to Section 289c, Paragraph 3, \nSentence 1, Items 3 and 4 of the HGB that are very likely to have \nor will have serious negative impacts on ESG aspects. \nE.ON places an emphasis on analyzing its climate risks, in part \nbecause of E.ON’s support of the recommendations of the Task \nForce on Climate-Related Financial Disclosures (“TCFD“). \nSafeguarding its assets against climate-change impacts and the \nclimate resilience of its business model are economically relevant \nto E.ON. Our analysis therefore includes both physical risks (direct \nimpacts of climate change, such as extreme weather and rising \ntemperatures) and transitory risks resulting from the transition to \na low-carbon and more climate-resilient economy (such as \nchanges in consumer preferences, the regulatory environment, and \ncarbon pricing).')], 'context': ["The annual report of E.ON does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [2]}} {'rag_agent': {'context_report': [Document(id='bfcc7a04-a93c-4932-a884-26c8bd1db34f', metadata={'company': 'qiagen', 'year': 2023}, page_content='C2.3, C2.3b, C2.4, C2.4a\nImpact of climate-related risks and opportunities on the organization’s business, strategy and financial \nplanning\nC2.3, C2.3b, C 2.4, C2.4a, C3.1, C3.3, C3.4\nResilience of the organization’s strategy, taking into consideration different climate-related scenarios, \nincluding a 2°C or lower scenario\nC3.1, C3.2, C3.2a, C3.2b\nRisk Management Organization’s processes for identifying and assessing climate-related risks C2.1, C2.1a, C2.1b, C2.2, C2.2a\nOrganization’s processes for managing climate related risks C2.2, C2.2a\nHow processes for identifying, assessing and managing climate-related risks are integrated into the \norganization’s overall risk management\nC2.2, C2.')], 'context': ["The annual report of Qiagen does not provide any information about the topic 'risks corporations face due to climate change'."], 'context_amount': [1]}} {'rag_agent': {'context_report': [Document(id='c932e3b7-b53e-4f53-bc63-1311ce5f962a', metadata={'company': 'henkel', 'year': 2023}, page_content='We assign the highest pr iority to the health and safety of our customers, \nconsumers and employees. \nLong-term risks arise in particular from accelerated climate change, water scarcity and restrictions on disposable \nand, in particular, non-recyclable plastic packaging and product ingredients.\nHENKEL ANNUAL REPORT 2023 194\nTHE COMPANY \nSHARES AND BONDS \nCOMBINED MANAGEMENT \nREPORT \nCONSOLIDATED FINANCIAL \nSTATEMENTS \nFURTHER INFORMATION \nCREDITS \nCONTACTS \nFINANCIAL CALENDAR \nAccelerating climate change could have negative impacts on a wide range of countries, particularly through \nincreases in the frequency and severity of extreme weather events. In addition to physical risks, this develop-\nment may also give rise to socioeconomic, so-called “transition” risks, for example as a result of political \nmeasures such as regulations and taxes. A more detailed discussion of relevant potential climate-related risks \ncan be found in our Sustainability Report 2023 on pages 36 and 37. The information is aligned to the recom-\nmendations of the Task Force on Climate-related Financial Disclosures (TCFD).')], 'context': ['The annual report of Henkel does provide information about the risks corporations face due to climate change. It highlights that accelerated climate change poses long-term risks, particularly through increased frequency and severity of extreme weather events. These physical risks can lead to significant operational disruptions and impact supply chains. Additionally, the report mentions socioeconomic "transition" risks arising from political measures such as regulations and taxes aimed at addressing climate change. Henkel emphasizes the importance of prioritizing health and safety while navigating these challenges, and further details can be found in their Sustainability Report 2023, which aligns with the recommendations of the Task Force on Climate-related Financial Disclosures (TCFD).'], 'context_amount': [1]}} {'rag_agent': {'context_report': [Document(id='b61f95c0-02ac-47d7-8202-51d170329783', metadata={'company': 'heidelberg-materials', 'year': 2023}, page_content='Describe the board’s oversight of climate-related risks \nand\xa0\u2003opp\nortunities \n CDP\tQuestionnaire ( C1.1.a, C1.1b) \nPages\u20031\n2–18,\u20031\n17,\u20031\n47–151,\u20031\n72–174\nDescribe management’s role in assessing and managing \nclimate- re\nlated risks and opportunities \n CDP\tQuestionnaire (C 1.2) \nPages 12–13, 24, 117, 147–151\nStrategy\nDisclosure focus area : Disclose the actual and potential impacts of climate-related risks and opportunities on the organisation’s \n\u2003bu\nsinesses,\u2003s\ntrategy,\u2003a\nnd\u2003fi\nnancial\u2003p\nlanning\u2003w\nhere\u2003s\nuch\u2003i\nnformation\u2003i\ns\u2003m\naterial.\nWe give careful consideration to the risks and opportunities of \nclimate change for our industry.'), Document(id='73360fed-4339-46e6-ab4f-ed9f4ec71e10', metadata={'company': 'heidelberg-materials', 'year': 2023}, page_content='The risks arising from such climate-related \nclaims could be high, but cannot be estimated in more \ndetail\u2003at\u2003pr esent,\u2003gi ven\u2003th e\u2003wi de\u2003va riety\u2003of\u2003po tential\u2003\ncourses of such claims. As such, the risk assessment \nis\xa0unchanged \u2003co mpared\u2003wi th\u2003th e\u2003pr evious\u2003ye ar.\u2003We\u2003\n currently consider the risk of climate-related claims to \nbe\u2003l\now.\nSustainability and compliance risks\nAs part of its sustainable corporate governance, \nHeidelberg Materials makes a special commitment to \nprotect the environment and climate, preserve resourc -\nes, conserve biodiversity, and act in a socially respon -\nsible\u2003wa\ny.\u2003Co\nmpliance\u2003wi\nth\u2003ap\nplicable\u2003la\nw\u2003an\nd\u2003Gr\noup\u2003\nregulations is a part of our corporate culture and there -\nfore a task and an obligation for all employees.')], 'context': ["The annual report of Heidelberg Materials does not provide specific information about the topic 'risks corporations face due to climate change.' While it mentions the board's oversight of climate-related risks and opportunities, as well as management's role in assessing and managing these risks, it does not detail the actual and potential impacts of climate-related risks on the organization’s business, strategy, and financial planning. The report indicates that the risks from climate-related claims are currently considered low, but it does not elaborate on the broader spectrum of climate-related risks that corporations may face. Additionally, while the company emphasizes its commitment to sustainability and compliance, it does not quantify or specify the risks associated with climate change in detail."], 'context_amount': [2]}} {'rag_agent': {'context_report': [Document(id='d4ceda9f-5aad-4648-b0f7-888bd541714a', metadata={'company': 'rheinmetall', 'year': 2023}, page_content='To \nidentify and better assess risks from climate change more reliably, Rheinmetall carried out a comprehensive site-\nspecific assessment on its production sites again in the year under review using database content from a \nrenowned service provider in accordance with the parameters of the Task Forc e on Climate -related Financial \nDisclosure. In addition, a scenario analysis using parameters from the Intergovernmental Panel on Climate Change \n(IPCC) was already carried out for these production sites in the previous year for the historical, 2045 and 2070 \nperiods, thereby analyzing the sites’ exposure to physical risks in four different global warming scenarios. We are\nLetter to shareholders Combined management report Consolidated financial statement Further information \n Risks and opportunities \n Significant corporate risks \nRHEINMETALL ANNUAL REPORT 2023 101 \nmaking a contribution to prevention with some of our products in civil business sectors and by successively \nreducing our CO2 emissions as part of energy and carbon management. We have set ourselves the ambitious goal \nof being carbon neutral by 2035.'), Document(id='9c3e5732-5d26-40c5-b246-70b97828c394', metadata={'company': 'rheinmetall', 'year': 2023}, page_content='The organization aims to establish the management of greenhouse \ngas emissions as a key economic success and risk factor in companies. Each year, on behalf of more than 500 \ninstitutional investors, the CDP collects information on corporate strategies to combat climate change and \ncompany-specific greenhouse emissions. In the Climate Change Questionnaire, alongside questions on the \norganization, targets, projects and programs, companies are surveyed in respect to information about risks and \nopportunities of climate changes and measures in the area of climate protection. Rhe inmetall again took part in \nthe CDP’s demanding sustainability rating in the year under review and improved its score from “D” to “B,” which \nis above the industry average (score C). \nTCFD \nThe four-pillar framework of the TCFD of the G20 Financial Stability Board helps companies both in integrating the \nopportunities and mitigating the risks of climate change into their business and in reporting on them consistently. \nPhysical risks result from long -term changes of climatic and ecological conditions (e.g.')], 'context': ["The annual report of Rheinmetall provides insights into the risks corporations face due to climate change, particularly through their comprehensive site-specific assessments and scenario analyses. These assessments, conducted in accordance with the Task Force on Climate-related Financial Disclosure (TCFD) parameters, help identify and evaluate physical risks associated with climate change at their production sites. By analyzing exposure to various global warming scenarios, Rheinmetall aims to understand the long-term impacts of climate change on their operations.\n\nAdditionally, the report highlights the importance of managing greenhouse gas emissions as a critical economic success and risk factor. Rheinmetall's participation in the CDP's sustainability rating and their improvement in score indicates a proactive approach to addressing climate-related risks and opportunities. The company is also committed to reducing CO2 emissions and achieving carbon neutrality by 2035, which reflects their recognition of climate change as a significant risk that requires strategic management.\n\nOverall, Rheinmetall's efforts to assess and mitigate climate-related risks demonstrate their awareness of the potential impacts of climate change on their business and their commitment to sustainability."], 'context_amount': [2]}} {'rag_agent': {'context_report': [Document(id='26bbbcb9-15d8-4e16-85cf-7a3e2af847e2', metadata={'company': 'airbus', 'year': 2023}, page_content='1.2.1 the Company’s \napproach to sustainability\n1.2.2 Climate change\nC1.1a, C1.1b, C1.1d\nDescribe management’s role in assessing and \nmanaging climate-related risks and opportunities C1.2\nStrategy\nDescribe the climate-related risks and opportunities \nthe organisation has identified over the short, medium, \nand long term\nRisk Factors\xa0– Environment, \nHuman Rights, Health & \nSafety Risks\n1.2.2 Climate Change\nsee the “Notes to the IFRS \nConsolidated Financial \nStatements” (Note\xa03: \nClimate impacts)\nC2.3, C2.3a, C2.4, C2.4a\nDescribe the impact of climate-related risks and \nopportunities on the organisation’s businesses, \nstrategy, and financial planning.'), Document(id='82910dd3-248a-4c5d-be1a-55e446ebca71', metadata={'company': 'airbus', 'year': 2023}, page_content='If the ambition is perceived as unattainable or if \nthe Company is not able to deliver on its ambition, this could \nresult in reputational damage leading to less investment, loss of \nrevenues and reduced attractiveness. A similar situation could \noccur if the Company’s environmental performance is not on \npar with its expressed ambition.\nPhysical\xa0– Acute: Extreme weather events may impact \nthe\xa0Company’s products and its operations\nThe foreseen consequences of climate change include more \nfrequent extreme weather events, such as drought, dust storms, \nextreme temperatures, extreme winds, flood, hail storms, \nlandslides, hurricanes, tornadoes, cyclones and wildfires. \nThese could negatively impact the Company’s products and \nits operations (including but not limited to route delays and safe \naircraft operations), land assets and infrastructure as well as \nemployees’ safety (and people’s safety generally).\nThe above consequences and impacts may result in production \nor other operational disruptions leading to lost revenues, \nreduced profits, and losses.')], 'context': ["The annual report of Airbus outlines several climate-related risks that the corporation faces, which can significantly impact its operations, strategy, and financial planning. Key risks include:\n\n1. **Reputational Risks**: If Airbus's sustainability ambitions are perceived as unattainable or if the company fails to meet its environmental performance goals, it could suffer reputational damage. This could lead to decreased investment, loss of revenues, and a diminished attractiveness to stakeholders.\n\n2. **Physical Risks**: The company is vulnerable to acute physical risks associated with climate change, such as extreme weather events. These events—ranging from droughts and floods to hurricanes and wildfires—can disrupt operations, affect product safety, and compromise employee safety. Such disruptions may result in production delays, operational inefficiencies, and ultimately, financial losses.\n\n3. **Operational Disruptions**: The anticipated increase in extreme weather events could lead to significant operational challenges, including route delays and safety concerns for aircraft operations. This could further exacerbate financial impacts through lost revenues and reduced profits.\n\nOverall, Airbus recognizes that climate change poses both risks and opportunities, and management plays a crucial role in assessing and addressing these challenges to ensure the company's long-term sustainability and resilience."], 'context_amount': [2]}} {'rag_agent': {'context_report': [Document(id='4c22ee62-360d-43bb-a296-b47e2bae3afe', metadata={'company': 'vonovia', 'year': 2023}, page_content='We have assessed the corre-\nsponding ”risk of business continuity in disasters/crisis \nsituations” as being associated with an amount of loss of \n€\xa05–40\xa0million (2022: €\xa05–40\xa0million) and a probability of \noccurrence of 5–39% (2022: 5–39%). To allow us to analyze \nand assess potential long-term implications of climate \nchange (i.e., those extending beyond the usual risk manage-\nment observation period of five years), we have developed a \nclimate risk tool that maps the internationally recognized \nclimate change scenarios developed by the Intergovernmen-\ntal Panel on Climate Change (IPCC).\u2009\nTransition risks and physical climate risks could potentially \nhave a negative impact on the Group’s net assets, financial \nposition and results of operations and could make the \nestimates used in an accounting context less certain.'), Document(id='6748518c-e112-48f1-ac7d-a4d26d8cd021', metadata={'company': 'vonovia', 'year': 2023}, page_content='Additional estimates and assumptions mainly relate to the \nuniform definition of useful lives, the assumptions made on \nthe value of land and buildings, the recognition and mea-\nsurement of provisions as well as the realization of future tax \nbenefits.\nClimate risks have an impact on Vonovia’s business model \nand strategy. They are addressed in particular by the climate \npath that the company has mapped out, but also by appro-\npriate estimates and assumptions in key items of the com-\npany’s net assets, financial position and results of opera-\ntions. Climate risks can have a potentially negative impact \nand result in increased estimation uncertainties.\nPhysical climate risks refer to longer-term shifts in general \nclimatic conditions. Climate events such as floods, earth-\nquakes, extreme weather events, etc. \u2009could have an impact \non our real estate portfolio and require specific crisis man-\nagement measures. Climate transition risks describe the \neffects that can arise for companies due to the process of \ntransformation towards a more sustainable economic \nsystem.')], 'context': ["The annual report of Vonovia provides insights into the risks corporations face due to climate change, highlighting both physical and transition risks. Physical climate risks, such as floods, earthquakes, and extreme weather events, pose a threat to the company's real estate portfolio and necessitate specific crisis management measures. These risks are assessed with a potential loss of €5–40 million and a probability of occurrence between 5–39%. \n\nOn the other hand, transition risks arise from the shift towards a more sustainable economic system, which could negatively impact the Group’s net assets, financial position, and operational results. The report emphasizes that these climate risks can lead to increased estimation uncertainties in accounting, affecting assumptions related to the useful lives of assets, land and building values, and the realization of future tax benefits.\n\nTo address these challenges, Vonovia has developed a climate risk tool that aligns with the climate change scenarios established by the Intergovernmental Panel on Climate Change (IPCC). This proactive approach aims to mitigate the long-term implications of climate change on the company's business model and strategy."], 'context_amount': [2]}} {'rag_agent': {'context_report': [Document(id='9da8de84-a625-43ac-a82d-603d1012da12', metadata={'company': 'siemens-energy', 'year': 2023}, page_content='Annual Report 2023: \n• Risk Management* \n \nGroup Non-Financial Statement \n2023: \n• Basis of Preparation \n \n(* covering only short-term \nclimate related risks) \nSustainability Report 2023: \n• Strategic focus \n• Annex - Task Force on Climate -\nRelated Financial Disclosures \n(TCFD) (see Climate Change \nGovernance, Management \napproach to climate-related risks \nand opportunities) \n \nStrategy \n \nDisclose the actual and potential \nimpacts of climate-related risks \nand opportunities on the organi-\nzation’s businesses, strategy, and \nfinancial planning where such in-\nformation is material. \na. Describe the climate-re-\nlated risks and opportuni-\nties the organization has \nidentified over the short, \nmedium, and long term.'), Document(id='83a709d5-d22d-4199-9710-e665f30ecdbf', metadata={'company': 'siemens-energy', 'year': 2023}, page_content='Such \ninvestigations may also adversely affect existing private business \nrelationships and our ability to pursue potentially important strategic \nprojects and transactions, such as strategic alliances, jo int ventures or \nother business alliances. In addition, third parties, including our compe-\ntitors, could initiate significant litigation. Furthermore, we might be \nexposed to compliance risks in relation to recently acquired operations \nthat are in the proces s of integration. Along with other measures, we \nhave a state -of-the-art global compliance organization in place to \nmitigate these risks, which conducts, among other things, compliance \nrisk mitigation processes such as comprehensive compliance trainings, \ncompliance risk assessments, and internal audit activities. \nClimate-related risks \nClimate change and decarbonization trend - The impacts of climate \nchange might have significant effects on our company throughout the \nentire value chain, such as markets, technologies, policy and legal, \nreputation, as well as climate -related physical impacts (e.g., from \nincreasing extreme weather events) on our sites, portfolio or supply \nchains. These changes will be gradual over several years or decades.')], 'context': ["The annual report of Siemens Energy outlines several climate-related risks that corporations face due to climate change. These risks can be categorized into various areas:\n\n1. **Market Risks**: The transition towards decarbonization and changing market dynamics can significantly impact Siemens Energy's business operations and market positioning. As consumer preferences shift towards sustainable solutions, the company must adapt to remain competitive.\n\n2. **Technological Risks**: The need for innovation in response to climate change may require substantial investment in new technologies. Failure to keep pace with technological advancements could hinder the company's ability to meet market demands.\n\n3. **Policy and Legal Risks**: As governments implement stricter regulations to combat climate change, Siemens Energy may face compliance risks, particularly in relation to recently acquired operations. Non-compliance could lead to legal challenges and financial penalties.\n\n4. **Reputational Risks**: The company's commitment to sustainability and climate action is crucial for maintaining its reputation. Any perceived failure to address climate-related issues could damage relationships with stakeholders, including customers and investors.\n\n5. **Physical Risks**: Climate change can lead to extreme weather events that may disrupt operations, affect supply chains, and damage infrastructure. These physical impacts pose a direct threat to the company's assets and operational continuity.\n\nOverall, Siemens Energy recognizes that climate-related risks are multifaceted and can have significant implications for its strategy, financial planning, and overall business resilience. The company is actively working to identify and mitigate these risks through a comprehensive risk management approach."], 'context_amount': [2]}} {'count_context': {'context_count': np.int64(15)}} {'generate_answer': {'final_answer': 'Corporations face several risks due to climate change, which can be categorized into physical, transition, and reputational risks:\n\n1. **Physical Risks**: These include acute risks from extreme weather events (e.g., floods, droughts, hurricanes) that can disrupt operations, damage infrastructure, and affect supply chains.\n\n2. **Transition Risks**: As the economy shifts towards sustainability, companies may face regulatory changes, market dynamics, and technological advancements that require adaptation. This includes compliance with stricter environmental regulations and the need for innovation.\n\n3. **Reputational Risks**: Companies risk damage to their reputation if they fail to meet sustainability goals or are perceived as not addressing climate-related issues adequately, which can impact stakeholder relationships and investment.\n\nSpecific examples from DAX 40 companies include Airbus, which highlights operational disruptions and reputational risks, and Siemens Energy, which outlines market, technological, policy, and physical risks. Vonovia also addresses both physical and transition risks related to its real estate portfolio.'}} ----------------- Answer: Corporations face several risks due to climate change, which can be categorized into physical, transition, and reputational risks: 1. **Physical Risks**: These include acute risks from extreme weather events (e.g., floods, droughts, hurricanes) that can disrupt operations, damage infrastructure, and affect supply chains. 2. **Transition Risks**: As the economy shifts towards sustainability, companies may face regulatory changes, market dynamics, and technological advancements that require adaptation. This includes compliance with stricter environmental regulations and the need for innovation. 3. **Reputational Risks**: Companies risk damage to their reputation if they fail to meet sustainability goals or are perceived as not addressing climate-related issues adequately, which can impact stakeholder relationships and investment. Specific examples from DAX 40 companies include Airbus, which highlights operational disruptions and reputational risks, and Siemens Energy, which outlines market, technological, policy, and physical risks. Vonovia also addresses both physical and transition risks related to its real estate portfolio.
Deployment¶
LangGraph Studio significantly enhances the deployment of AI agents by providing a comprehensive development environment tailored for LangGraph applications. It allows developers to visualize, interact with, and debug agent workflows, enabling the creation of scalable, production-ready AI agents with features like stateful computation, long-term memory, and human-in-the-loop capabilities.
!cd studio && langgraph dev
Wait for LangSmith opening automatically in your default browser.