# 09. RAG + Image Generator Agent (Reporting)

## RAG + Image Generator Agent (Reporting) <a href="#rag-image-generator-agent" id="rag-image-generator-agent"></a>

In this tutorial, we will create an agent that creates reports through web search, PDF document-based search (RAG), image generation, and more.

**Reference**

* [Agent Toolkits](https://api.python.langchain.com/en/latest/community/agent_toolkits.html)
* [Tools](https://python.langchain.com/docs/integrations/tools/)

```python
# Configuration file for managing API keys as environment variables
from dotenv import load_dotenv

# Load API key information
load_dotenv()
```

```
 True 
```

```python
# LangSmith Set up tracking. https://smith.langchain.com
# !pip install -qU langchain-teddynote
from langchain_teddynote import logging

# Enter a project name.
logging.langsmith("CH15-Agent-Projects")
```

```
 Start tracking LangSmith. 
[Project name] 
CH15-Agent-Projects 
```

### Tool definition <a href="#id-1" id="id-1"></a>

#### Web Search Tool: Tavily Search <a href="#tavily-search" id="tavily-search"></a>

LangChain has built-in tools that make Tavily search engines easy to use as tools.

API KEY must be issued to use Tavily Search.

* [Tavily Search API issued](https://app.tavily.com/sign-in)

Register the issued API KEY for environmental variables as follows:

`.env` Register as follows in the file:

* `TAVILY_API_KEY=발급 받은 Tavily API KEY 입력`

```python
from langchain_community.tools.tavily_search import TavilySearchResults

# Create an instance of the TavilySearchResults class.
# k=6 means that we will retrieve up to 6 search results.
search = TavilySearchResults(k=6)
```

#### Document-based document search tool: Retriever <a href="#retriever" id="retriever"></a>

It also generates retrievers to perform queries on our data.

**Documents utilized for practice**

Software Policy Institute (SPRi)-December 2023

* Author: Jaeheung Lee (AI Policy Institute Office Liability Institute), Lee Ji-soo (AI Policy Lab Yi Phyang Institute)
* Link: <https://spri.kr/posts/view/23669>
* File name: `SPRI_AI_Brief_2023년12월호_F.pdf`

*Files downloaded for practice `data` Please copy to folder*

The following creates a retriever, and a tool based on the retriever you created.

First, load the document, split it, then create a retriever.

```python
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_community.vectorstores import FAISS
from langchain_openai import OpenAIEmbeddings
from langchain.document_loaders import PyMuPDFLoader

# Load PDF file. Enter path to file.
loader = PyMuPDFLoader("data/SPRI_AI_Brief_2023년12월호_F.pdf")

# Split your document using the text splitter.
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=100)

# Load and split the document.
split_docs = loader.load_and_split(text_splitter)

# Create a VectorStore.
vector = FAISS.from_documents(split_docs, OpenAIEmbeddings())

# Create a Retriever.
retriever = vector.as_retriever()
```

The following defines retriever as a tool.

At this time, `document_prompt` Defines a template that displays the contents of the document.

**Reference**

* The default value of the document `page_content` Just mark.
* Therefore, in order to display the page number or source light of the document later, the template must be defined separately.

```python
from langchain.tools.retriever import create_retriever_tool
from langchain_core.prompts import PromptTemplate

# Defines a template that displays the content of a document.
document_prompt = PromptTemplate.from_template(
    "<document><content>{page_content}</content><page>{page}</page><filename>{source}</filename></document>"
)

# Define retriever as a tool.
retriever_tool = create_retriever_tool(
    retriever,
    name="pdf_search",
    description="use this tool to search for information in the PDF file",
    document_prompt=document_prompt,
)
```

#### DallE image creation tool <a href="#dalle" id="dalle"></a>

This time create a Dall-E image creation tool.

**Main properties**

* `model` : DALL-E model name to use (default: "dall-e-2", "dall-e-3")
* `n` : Number of images to create (default: 1)
* `size` : Image size to create
  * "dall-e-2": "1024x1024", "512x512", "256x256"
  * "dall-e-3": "1024x1024", "1792x1024", "1024x1792"
* `style` : Style of the image to be created (default: "natural", "vivid")
* `quality` : Quality of the image to be created (default: "standard", "hd")
* `max_retries` : Maximum number of retries at creation

```python
from langchain_community.utilities.dalle_image_generator import DallEAPIWrapper
from langchain.tools import tool

# Create a DallE API Wrapper.
dalle = DallEAPIWrapper(model="dall-e-3", size="1024x1024", quality="standard", n=1)


# Define DallE API Wrapper as a tool.
@tool
def dalle_tool(query):
    """use this tool to generate image from text"""
    return dalle.run(query)
```

#### File management tools <a href="#id-2" id="id-2"></a>

**File management tools**

* `CopyFileTool` : Copy file
* `DeleteFileTool` : Delete file
* `FileSearchTool` : File Search
* `MoveFileTool` : Move file
* `ReadFileTool` : Read file
* `WriteFileTool` : Write file
* `ListDirectoryTool` : Directory list lookup

```python
from langchain_community.agent_toolkits import FileManagementToolkit

# Set working directory path
working_directory = "tmp"

# Create file management tools (write, read files, list directories)
file_tools = FileManagementToolkit(
    root_dir=str(working_directory),
    selected_tools=["write_file", "read_file", "list_directory"],
).get_tools()

# Generated file management tool output
file_tools
```

```
 [WriteFileTool (root_dir='tmp'), ReadFileTool (root_dir='tmp'), ListDirectoryTool (root_dir='tmp')] 
```

Now, put all the tools together.

```python
tools = file_tools + [
    retriever_tool,
    search,
    dalle_tool,
]

# Output the final tool list
tools
```

```
 [WriteFileTool (root_dir='tmp'), ReadFileTool (root_dir='tmp'), ListDirectoryTool (root_dir='tmp'), Tool (name='pdf_search', description=  , func=functools.partial(  , retriever= VectorStoreRetriever (tags=['FAISS','OpenAIEmbeddings'], vectorstore=  ), document_prompt=PromptTemplate (input_variables=['page','page_content','source'], template='  {page_content}  {page}  {source}  '), document_separator='\n\n'), coroutine=functools.partial(  , retriever= VectorStoreRetriever (tags=['FAISS','OpenAIEmbeddings'], vectorstore=  ), document_prompt=PromptTemplate (input_variables=['page','page_content','source'], template='  {page_content}  {page}  {source}  '), document_separator='\n\n')), TavilySearchResults(), StructuredTool (name='dalle_tool', description='use this tool to general image from text', args_schema=  , func=  )] 
```

### Agent creation <a href="#agent" id="agent"></a>

```python
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables.history import RunnableWithMessageHistory
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_community.chat_message_histories import ChatMessageHistory
from langchain_openai import ChatOpenAI
from langchain_teddynote.messages import AgentStreamParser

# Create a dictionary to store session_id
store = {}

# Generate prompt
# Prompts provide text that describes to the agent what the model should do (enter the name of the tool and its role).
prompt = ChatPromptTemplate.from_messages(
    [
        (
            "system",
            "You are a helpful assistant. "
            "You are a professional researcher. "
            "You can use the pdf_search tool to search for information in the PDF file. "
            "You can find further information by using search tool. "
            "You can use image generation tool to generate image from text. "
            "Finally, you can use file management tool to save your research result into files.",
        ),
        ("placeholder", "{chat_history}"),
        ("human", "{input}"),
        ("placeholder", "{agent_scratchpad}"),
    ]
)


# Create an LLM
llm = ChatOpenAI(model="gpt-4o-mini")

# Create Agent
agent = create_tool_calling_agent(llm, tools, prompt)

# Create AgentExecutor
agent_executor = AgentExecutor(
    agent=agent,
    tools=tools,
    verbose=False,
    handle_parsing_errors=True,
)


# Function to retrieve session records based on session_id
def get_session_history(session_ids):
    if session_ids not in store:  # If session_id is not in the store
        # Create a new ChatMessageHistory object and save it to the store.
        store[session_ids] = ChatMessageHistory()
    return store[session_ids]  # Returns the session record for the given session ID.


# Create an agent with added chat message history.
agent_with_chat_history = RunnableWithMessageHistory(
    agent_executor,
    # Conversation session_id
    get_session_history,
    # Key: "input" where the question in the prompt is entered
    input_messages_key="input",
    # The key that the prompt's message is entered into: "chat_history"
    history_messages_key="chat_history",
)

# Creating a stream parser
agent_stream_parser = AgentStreamParser()
```

Now, let's run the agent.

```python
# Running the agent
result = agent_with_chat_history.stream(
    {
        "input": "Please find useful information related to `generative AI` developed by Samsung Electronics in the PDF document and organize it in bullet points. "
        "Please write in Korean."
        "Next, create a new `report.md` file and save the organized content. \n\n"
        "how to write: \n"
        "1. Write an appropriate title in markdown header 2 size. \n"
        "2. Enter the page number and file name of the extracted PDF document (example): page 10, filename.pdf). \n"
        "3. Write a well-organized bullet point. \n"
        "4. When you're done writing, save the file as `report.md`. \n"
        "5. Please read and print the last saved `report.md` file. \n"
    },
    config={"configurable": {"session_id": "abc123"}},
)

print("Agent execution results:")
for step in result:
    agent_stream_parser.process_agent_steps(step)
```

```
 Agent run results: 
[Tool call] 
Tool: pdf_search 
query: Samsung-generated AI 
Log:  
Invoking: `pdf_search` with `{'query':'Triple-generated AI'}` 

[Observation content] 
Observation:   SPRi AI Brief |  
2023-December 
10 
Samsung Electronics unveils self-developed AI ‘Samsung Gauss ’ 
n Create a self-development consisting of 3 models of languages, codes, and images that the Samsung can operate on the on-Device  
AI model ‘Samsung Gauss ’ released 
(...sway...) 
High-resolution switching of low-resolution images also supports 
n IT specialization TechRepublic has emerged as a major technology trend,  12  data/SPRI_AI_Brief_2023 December _F.pdf 

 High-resolution switching of low-resolution images also supports 
n IT specialization TechRepublic has emerged as a major technology trend,  
(...sway...) 
TechRepublic, Samsung Gauss: Samsung Research Reveals Generative AI, 2023.11.08.  12  data/SPRI_AI_Brief_2023 December _F.pdf 

 SPRi AI Brief |  
2023-December 
4 
US courts dismiss copyright lawsuits filed by artists to AI companies created 
(...sway...) 
Since the image was trained using the work, the claim that it is a derivative image of the work lacks personality.  
Point out  6  data/SPRI_AI_Brief_2023 December _F.pdf 

 20  data/SPRI_AI_Brief_2023 December _F.pdf 

[Tool call] 
Tool: write_file 
file_path: report.md 
text: ## Generic AI of Samsung ‘Samsung Gauss’ Related Information 

-**Page number**: 10, 12  
-**File name**: SPRI_AI_Brief_2023 December issue_F.pdf  

-The Samsung Electronics unveils the generated AI model ‘Samsung Gauss ’ that can operate on the Ondevice.  
-Samsung Gauss consists of 3 models of language, code and images.  
-Integrated by the operation of the on-device, there is no risk of user information leakage.  
-Samsung Gauss will be phased in various products.  
-The language model supports mail writing, document summarization, translation, etc., with cloud and on-device models.  
-The code model ‘Code.i’ is optimized for software development with an interactive interface.  
-The image model provides the ability to create creative images and convert low-resolution images to high resolution.  
-From 2024, the Gaussian-mounted Samsung smartphone is expected to be competitive. 
Log:  
Invoking: `write_file` with `{'file_path':'report.md','text':'## Samsung's Generated AI ‘Samsung Gauss’ Related Information\n\n- ** Page Number**: 10, 12 \n- *RI*sway...) 
Provides the ability to create righteous images and convert low-resolution images to high resolution. \n- From 2024, Gaussian-mounted Samsung smartphones are expected to be competitive.'}` 

[Observation content] 
Observation: File written successfully to report.md. 
[Tool call] 
Tool: read_file 
file_path: report.md 
Log:  
Invoking: `read_file` with `{'file_path':'report.md'}` 

[Observation content] 
Observation: ## Generating AI of Samsung ‘Samsung Gauss’ Related Information 
(...sway...) 
-From 2024, the Gaussian-mounted Samsung smartphone is expected to be competitive. 

[Final answer] 
The following is information about the generated AI'Samsung Gauss' developed by the Samsung. 

## Generating AI of Samsung ‘Samsung Gauss ’ Related Information 

-**Page number**: 10, 12  
-**File name**: SPRI_AI_Brief_2023 December issue_F.pdf  

-The Samsung Electronics unveils the generated AI model ‘Samsung Gauss ’ that can operate on the Ondevice.  
(...sway...) 
-From 2024, the Gaussian-mounted Samsung smartphone is expected to be competitive.  

This content was stored in the `report.md` file. 
```

Report file created `report.md` When I check the contents of ), it is output as follows.

```python
Copy# Request for report creation.
result = agent_with_chat_history.stream(
    {
        "input": "`report.md` Open the file and print its contents. "
        "Create a professional-level report based on the output."
        "The report should consist of three sections in total:\n"
        "1. Abstract: Please write an abstract of your report in approximately 300 characters.\n"
        "2. Key Content: Write down the key content of the report. Add a well-organized table in markdown format. "
        "3. Final Conclusion: Write the final conclusion of your report. Indicate the source (file name, url, etc.)."
        "Finally, save the final result to the file `report-2.md`."
    },
    config={"configurable": {"session_id": "abc123"}},
)

print("Agent execution results:")
for step in result:
    agent_stream_parser.process_agent_steps(step)
```

![](https://wikidocs.net/images/page/262612/report-agent-02.png)

Updated report files ( `report.md` When I check the contents of ), it is output as follows.

```
 Agent run results: 
[Tool call] 
Tool: tavily_search_results_json 
query: Samsung-generated AI 
Log:  
Invoking: `tavily_search_results_json` with `{'query':'Triple-generated AI'}` 

[Observation content] 
Observation: [{'url':'https://www.yna.co.kr/view/AKR20231108041400003','content': "The generated artificial intelligence (AI) model'Samsung Gauss' developed by the Samsung [005930] was first released. Samsung plans to leverage Samsung Gauss to increase the productivity of its employees, while providing a new user experience by step-by-step product-generated AI models.” }, 
(...sway...) 
'Samsung Developer Conference Korea 2023' (SDC23 Korea) is being held in the Seo Seo Seo Seo Seo Cho in Seoul. The photo introduces the AI model'Samsung Gauss', which is created by a migrant executive. 2023.11.14 mjkang@yna.co.kr" }] 

[Tool call] 
Tool: read_file 
file_path: report.md 
Log:  
Invoking: `read_file` with `{'file_path':'report.md'}` 

[Observation content] 
Observation: ## Generating AI of Samsung ‘Samsung Gauss’ Related Information 

-**Page number**: 10, 12  
-**File name**: SPRI_AI_Brief_2023 December issue_F.pdf  

-The Samsung Electronics unveils the generated AI model ‘Samsung Gauss ’ that can operate on the Ondevice.  
(...sway...) 
-From 2024, the Gaussian-mounted Samsung smartphone is expected to be competitive. 

[Tool call] 
Tool: write_file 
file_path: report.md 
text: ## Generated AI of Samsung ‘Samsung Gauss’ Related Web Search Information 

-**Source**: [Union News] (https://www.yna.co.kr/view/AKR20231108041400003) 
-The generated AI model'Samsung Gauss' developed by the Samsung Electronics was first released. 
(...sway...) 
-**Source**: [Union News] (https://www.yna.co.kr/view/AKR20231114028651003) 
-Samsung Gauss was introduced at'Samsung Developer Conference Korea 2023' at the Seonggwon Prison in 14 November 2023. 

append: True 
Log:  
Invoking: `write_file` with `{'file_path':'report.md','text': "## Generated AI of Samsung ‘Samsung Gauss ’ Related Web Search Information\n\n- **Source**: [Coal News] (https://www.yna.co.kr/view/AKR20231108041400003)\n-sway...) 
(https://www.yna.co.kr/view/AKR20231114028651003)\n- On November 14, 2023, Samsung Gauss was introduced at'Samsung Developer Conference Korea 2023' in the Episode of Samsung. 

[Observation content] 
Observation: File written successfully to report.md. 

[Tool call] 
Tool: read_file 
file_path: report.md 
Log:  
Invoking: `read_file` with `{'file_path':'report.md'}` 

[Observation content] 
Observation: ## Generating AI of Samsung ‘Samsung Gauss’ Related Information 

-**Page number**: 10, 12  
-**File name**: SPRI_AI_Brief_2023 December issue_F.pdf  

-The Samsung Electronics unveils the generated AI model ‘Samsung Gauss ’ that can operate on the Ondevice.  
(...sway...) 
-From 2024, the Gaussian-mounted Samsung smartphone is expected to be competitive.## Generating AI of Samsung ‘Samsung Gauss ’ Related Web Search Information 

-**Source**: [Union News] (https://www.yna.co.kr/view/AKR20231108041400003) 
-The generated AI model'Samsung Gauss' developed by the Samsung Electronics was first released. 
(...sway...) 
-**Source**: [Union News] (https://www.yna.co.kr/view/AKR20231114028651003) 
-Samsung Gauss was introduced at'Samsung Developer Conference Korea 2023' at the Seonggwon Prison in 14 November 2023. 

[Final answer] 
The following is the contents of the updated `report.md` file. 

## Generating AI of Samsung ‘Samsung Gauss ’ Related Information 

-**Page number**: 10, 12  
-**File name**: SPRI_AI_Brief_2023 December issue_F.pdf  

-The Samsung Electronics unveils the generated AI model ‘Samsung Gauss ’ that can operate on the Ondevice.  
(...sway...) 
-From 2024, the Gaussian-mounted Samsung smartphone is expected to be competitive.  

## Generating AI of Samsung ‘Samsung Gauss ’ Related Web Search Information 

-**Source**: [Union News] (https://www.yna.co.kr/view/AKR20231108041400003) 
-The generated AI model'Samsung Gauss' developed by the Samsung Electronics was first released. 
-The Samsung will plan to increase the employee's work productivity through this model and provide a new user experience by step-by-step on the product with a generated AI model. 
(...sway...) 
-**Source**: [Union News] (https://www.yna.co.kr/view/AKR20231114028651003) 
-Samsung Gauss was introduced at'Samsung Developer Conference Korea 2023' at the Seonggwon Prison in 14 November 2023. 
```

```python
# Update report files through web searches
result = agent_with_chat_history.stream(
    {
        "input": "This time, please search the web for information related to the ‘generative AI’ developed by Samsung Electronics and organize the search results. "
        "Please write in Korean."
        "next is `report.md` Open the file, read the existing content, and add the information you found by searching the web to the back of the file in the format you previously wrote. \n\n"
        "how to write    : \n"
        "1. Write an appropriate title in markdown header 2 size. \n"
        "2. Enter the source (url) of the information (Example: Source: Naver Encyclopedia). \n"
        "3. Create organized web search content. \n"
        "4. When you're done writing, save the file as `report.md`. \n"
        "5. Please read and print the `report.md` file that was saved last. \n"
    },
    config={"configurable": {"session_id": "abc123"}},
)

print("Agent execution results:")
for step in result:
    agent_stream_parser.process_agent_steps(step)
```

Next, let's update the report file via web search.

```
Agent run results: 
[Tool call] 
Tool: read_file 
file_path: report.md 
Log:  
Invoking: `read_file` with `{'file_path':'report.md'}` 

[Observation content] 
Observation: ## Generating AI of Samsung ‘Samsung Gauss’ Related Information 

-**Page number**: 10, 12  
-**File name**: SPRI_AI_Brief_2023 December issue_F.pdf  

-The Samsung Electronics unveils the generated AI model ‘Samsung Gauss ’ that can operate on the Ondevice.  
(...sway...) 
-From 2024, the Gaussian-mounted Samsung smartphone is expected to be competitive.## Generating AI of Samsung ‘Samsung Gauss ’ Related Web Search Information 

-**Source**: [Union News] (https://www.yna.co.kr/view/AKR20231108041400003) 
-The generated AI model'Samsung Gauss' developed by the Samsung Electronics was first released. 
(...sway...) 
-**Source**: [Union News] (https://www.yna.co.kr/view/AKR20231114028651003) 
-Samsung Gauss was introduced at'Samsung Developer Conference Korea 2023' at the Seonggwon Prison in 14 November 2023. 

[Tool call] 
Tool: write_file 
file_path: report-2.md 
text: # Samsung generated AI ‘Samsung Gauss’ report 

## One. summary 
The generated AI model'Samsung Gauss' developed by the Samsung Electronics works on an on-device and has features that minimize the risk of user information leakage. The model consists of three main models, including language, code, and images, and will be phased in various Samsung products. This report looks at the key content and expected effects of Samsung Gauss. 

## 2. Core content  
| Item | Content | 
|------|------| 
| Model name | Samsung Gauss | 
| Configuration model | Language model, code model, image model | 
| Features | Minimize the risk of information leakage due to on-device operation | 
| Language model features | Mail writing, document summary, translation, etc. | 
| Code Model | Code.i-Provides an interactive interface | 
| Image model function | Creative image creation, low resolution image high resolution conversion | 
| Coming Soon | Coming on Samsung smartphones from 2024 | 
| Main goals | Improve employee work productivity, provide new user experience | 

## 3. Finalism 
Samsung's generated AI'Samsung Gauss' is an important technology for the company's business innovation and is a model with applicability in various fields. This model is expected to transform the user experience in the future by providing a variety of features while protecting user information safely.  

**Source**: SPRI_AI_Brief_2023 December issue_F.pdf, [Union News] (https://www.yna.co.kr/view/AKR20231108041400003), [AITime] (https://www.aitimes.kr/news/articleView.html?idxno=29318), [ZDNet] (https://zdnet.co.kr/view/?no=20231108081251), [Two Wiki] (https://namu.wiki/w/삼성+가우스) 
append: False 
Log:  
Invoking: `write_file` with `{'file_path':'report-2.md','text': "# Generated AI of Samsung ‘Samsung Gauss’ Report\n\n## 1. Overview\n The generated AI model'Samsung Gauss' developed by the Samsung Electronics works on an on-device and has features that minimize the risk of user information leakage. The model consists of three main models, including language, code, and images, and will be phased in various Samsung products. This report looks at the core content and expected effects of Samsung Gauss.\n\n## 2. Core content \n| Item | Content |\n|------|------|\n| Model name | Samsung Gauss |\n| Configuration model |n| Code Model | Code.i-Provides an interactive interface |\n| Image model function | Creative image creation, low resolution image high resolution conversion |\n| Coming soon | 2024 Year Samsung Smartphone Coming on Finalist\n The generated AI of the Samsung's AI'Samsung Gauss' is an important technology for the company's business innovation and is a model with applicability in various fields. This model is expected to transform the user experience in the future by providing a variety of features while keeping user information safe. \n\n*****:  SPRI_AI_Brief_2023 December _F.pdf, [Union News] (https://www.yna.co.kr/view/AKR20231108041400003), [AI Times] (https://www.aitimes.kr/news/articleView.html?idxno=29318), [ZDNet] (https://zdnet.co.kr/view/?no=20231108081251), [Woody]] (https://namu.wiki/w/삼성+가우스)",'append': False}` 

[Observation content] 
Observation: File written successfully to report-2.md. 

[Tool call] 
Tool: read_file 
file_path: report-2.md 
Log:  
Invoking: `read_file` with `{'file_path':'report-2.md'}` 

[Observation content] 
Observation: # Samsung Generator's Generated AI ‘Samsung Gauss’ Report 

The generated AI model'Samsung Gauss' developed by the Samsung Electronics works on an on-device, minimizing the risk of user information leakage  
(...sway...) 
no=20231108081251), [Woody] (https://namu.wiki/w/삼성+가우스) 
[Final answer] 
Below is a professional report on the generated AI'Samsung Gauss' of the Samsung. 

# Samsung Electronics' Generated AI ‘Samsung Gauss’ Report 

## One. summary 
The generated AI model'Samsung Gauss' developed by the Samsung Electronics works on an on-device and has features that minimize the risk of user information leakage. The model consists of three main models, including language, code, and images, and will be phased in various Samsung products. This report looks at the key content and expected effects of Samsung Gauss. 

## 2. Core content  
| Item | Content | 
|------|------| 
| Model name | Samsung Gauss | 
| Configuration model | Language model, code model, image model | 
| Features | Minimize the risk of information leakage due to on-device operation | 
| Language model features | Mail writing, document summary, translation, etc. | 
| Code Model | Code.i-Provides an interactive interface | 
| Image model function | Creative image creation, low resolution image high resolution conversion | 
| Coming Soon | Coming on Samsung smartphones from 2024 | 
| Main goals | Improve employee work productivity, provide new user experience | 

## 3. Finalism 
Samsung's generated AI'Samsung Gauss' is an important technology for the company's business innovation and is a model with applicability in various fields. This model is expected to transform the user experience in the future by providing a variety of features while protecting user information safely.  

**Source**: SPRI_AI_Brief_2023 December issue_F.pdf, [Union News] (https://www.yna.co.kr/view/AKR20231108041400003), [AITime] (https://www.aitimes.kr/news/articleView.html?idxno=29318), [ZDNet] (https://zdnet.co.kr/view/?no=20231108081251), [Two Wiki] (https://namu.wiki/w/삼성+가우스) 

This report was stored in the `report-2.md` file. 
```

Newly written report files ( `report-2.md` When I check the contents of ), it is output as follows.

![](https://wikidocs.net/images/page/262612/report-agent-03.png)

Finally, let's request image creation based on the report content.

```python
# Request image creation.
result = agent_with_chat_history.stream(
    {
        "input": "`report-2.md` Open the file and print its contents. "
        "Create an image that matches the printed content. "
        "Add the URL of the image you created to the very top of your report in markdown format. "
        "Finally, save the final result to the file `report-3.md`."
    },
    config={"configurable": {"session_id": "abc123"}},
)

print("Agent execution resultsww:")
for step in result:
    agent_stream_parser.process_agent_steps(step)
```

```
 Agent run results: 
[Tool call] 
Tool: read_file 
file_path: report-2.md 
Log:  
Invoking: `read_file` with `{'file_path':'report-2.md'}` 

[Observation content] 
Observation: # Samsung Generator's Generated AI ‘Samsung Gauss’ Report 
(...sway...) 
[AI Times] (https://www.aitimes.kr/news/articleView.html?idxno=29318), [ZDNet] (https://zdnet.co.kr/view/?no=20231108081251), [Woody] (https://namu.wiki/w/삼성+가우스) 

[Tool call] 
Tool: dalle_tool 
query: A conceptual illustration of Samsung's generic AI model'Samsung Gauss', showcasing its features like language processing, code generation, and image creation, with a futuristic design and high-tech elements. 
Log:  
Invoking: `dalle_tool` with `{'query': "A conceptual illustration of Samsung's generic AI model'Samsung Gauss', showcasing its features like language processing, code generation, and image creation, with a futuristic` 

[Observation content] 
Observation: https://oaidalleapiprodscus.blob.core.windows.net/private/org-tXcEmZlh1cumsP4TP3SN0Pfg/user-YEkqOD0WDzdBJtrZ14HjLkAq/img-k07Q5YejGq3aSCob589gLGYR.png?st=2024-10-07T09%3A03%3A52Z&se=2024-10-07T11%3A03%3A52Z&sp=r&sv=2024-08-04&sr=b&rscd=inline&rsct=image/png&skoid=d505667d-d6c1-4a0a-bac7-5c84a87759f8&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2024-10-06T10%3A28%3A23Z&ske=2024-10-07T10%3A28%3A23Z&sks=b&skv=2024-08-04&sig=qsakVoPmVwou/dHFu/b472gpZ9bkBbIkoKxDmA7LSDk%3D 

[Tool call] 
Tool: write_file 
file_path: report-3.md 
text: ![Samsung Gauss AI Model] (https://oaidalleapiprodscus.blob.core.windows.net/private/org-tXcEmZlh1cumsP4TP3SN0Pfg/user-YEkqOD0WDzdBJtrZ14HjLkAq/img-k07Q5YejGq3aSCob589gLGYR.png?st=2024-10-07T09%3A03%3A52Z&se=2024-10-07T11%3A03%3A52Z&sp=r&sv=2024-08-04&sr=b&rscd=inline&rsct=image/png&skoid=d505667d-d6c1-4a0a-bac7-5c84a87759f8&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2024-10-06T10%3A28%3A23Z&ske=2024-10-07T10%3A28%3A23Z&sks=b&skv=2024-08-04&sig=qsakVoPmVwou/dHFu/b472gpZ9bkBbIkoKxDmA7LSDk%3D) 

# Samsung Electronics' Generated AI ‘Samsung Gauss’ Report 

## One. summary 
(...sway...) 
[ZDNet] (https://zdnet.co.kr/view/?no=20231108081251), [Woody] (https://namu.wiki/w/삼성+가우스) 
append: False 
Log:  
Invoking: `write_file` with `{'file_path':'report-3.md','text': "![Samsung Gauss AI Model] (https://oaidalleapiprodscus.blob.core.windows.net/private/org-tXcEmZlh1cumsP4TP3SN0Pfg/user-YEkqOD0WDzdBJtrZ14HjLkAq/img-k07Q5YejGq3aSCob589gLGYR.png?st=2024-10- 
(...sway...) 
[ZDNet] (https://zdnet.co.kr/view/?no=20231108081251), [Woody] (https://namu.wiki/w/삼성+가우스)",'append': False}` 

[Observation content] 
Observation: File written successfully to report-3.md. 

[Final answer] 
Below is the contents of the `report-3.md` file. 

# Samsung Electronics' Generated AI ‘Samsung Gauss’ Report 

## One. summary 
The generated AI model'Samsung Gauss' developed by the Samsung Electronics works on an on-device and has features that minimize the risk of user information leakage. The model consists of three main models, including language, code, and images, and will be phased in various Samsung products. This report looks at the key content and expected effects of Samsung Gauss. 

## 2. Core content  
| Item | Content | 
|------|------| 
| Model name | Samsung Gauss | 
| Configuration model | Language model, code model, image model | 
| Features | Minimize the risk of information leakage due to on-device operation | 
| Language model features | Mail writing, document summary, translation, etc. | 
| Code Model | Code.i-Provides an interactive interface | 
| Image model function | Creative image creation, low resolution image high resolution conversion | 
| Coming Soon | Coming on Samsung smartphones from 2024 | 
| Main goals | Improve employee work productivity, provide new user experience | 

## 3. Finalism 
Samsung's generated AI'Samsung Gauss' is an important technology for the company's business innovation and is a model with applicability in various fields. This model is expected to transform the user experience in the future by providing a variety of features while protecting user information safely.  

**Source**: SPRI_AI_Brief_2023 December issue_F.pdf, [Union News] (https://www.yna.co.kr/view/AKR20231108041400003), [AITime] (https://www.aitimes.kr/news/articleView.html?idxno=29318), [ZDNet] (https://zdnet.co.kr/view/?no=20231108081251), [Two Wiki] (https://namu.wiki/w/삼성+가우스) 
```

\
Last generated report file `report-3.md` If you check some of the contents of ), it will output as follows:

![](https://wikidocs.net/images/page/262612/report-agent-04.png)

<br>
