File size: 4,947 Bytes
17c6d62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!--Copyright 2023 The HuggingFace Team. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
rendered properly in your Markdown viewer.

-->

# μ—μ΄μ „νŠΈ & 도ꡬ [[agents-tools]]

<Tip warning={true}>

Transformers AgentλŠ” μ‹€ν—˜ 쀑인 APIμ΄λ―€λ‘œ μ–Έμ œλ“ μ§€ 변경될 수 μžˆμŠ΅λ‹ˆλ‹€. 
APIλ‚˜ 기반 λͺ¨λΈμ΄ 자주 μ—…λ°μ΄νŠΈλ˜λ―€λ‘œ, μ—μ΄μ „νŠΈκ°€ μ œκ³΅ν•˜λŠ” 결과물은 λ‹¬λΌμ§ˆ 수 μžˆμŠ΅λ‹ˆλ‹€.

</Tip>

μ—μ΄μ „νŠΈμ™€ 도ꡬ에 λŒ€ν•΄ 더 μ•Œμ•„λ³΄λ €λ©΄ [μ†Œκ°œ κ°€μ΄λ“œ](../transformers_agents)λ₯Ό κΌ­ μ½μ–΄λ³΄μ„Έμš”. 
이 νŽ˜μ΄μ§€μ—λŠ” κΈ°λ³Έ ν΄λž˜μŠ€μ— λŒ€ν•œ API λ¬Έμ„œκ°€ ν¬ν•¨λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€.

## μ—μ΄μ „νŠΈ [[agents]]

μš°λ¦¬λŠ” κΈ°λ³Έ [`Agent`] 클래슀λ₯Ό 기반으둜 두 κ°€μ§€ μœ ν˜•μ˜ μ—μ΄μ „νŠΈλ₯Ό μ œκ³΅ν•©λ‹ˆλ‹€:
- [`CodeAgent`]λŠ” ν•œ λ²ˆμ— λ™μž‘ν•©λ‹ˆλ‹€. μž‘μ—…μ„ ν•΄κ²°ν•˜κΈ° μœ„ν•΄ μ½”λ“œλ₯Ό μƒμ„±ν•œ λ‹€μŒ, λ°”λ‘œ μ‹€ν–‰ν•©λ‹ˆλ‹€.
- [`ReactAgent`]λŠ” λ‹¨κ³„λ³„λ‘œ λ™μž‘ν•˜λ©°, 각 λ‹¨κ³„λŠ” ν•˜λ‚˜μ˜ 생각, ν•˜λ‚˜μ˜ 도ꡬ 호좜 및 μ‹€ν–‰μœΌλ‘œ κ΅¬μ„±λ©λ‹ˆλ‹€. 이 μ—μ΄μ „νŠΈμ—λŠ” 두 κ°€μ§€ ν΄λž˜μŠ€κ°€ μžˆμŠ΅λ‹ˆλ‹€:
  - [`ReactJsonAgent`]λŠ” 도ꡬ ν˜ΈμΆœμ„ JSON으둜 μž‘μ„±ν•©λ‹ˆλ‹€.
  - [`ReactCodeAgent`]λŠ” 도ꡬ ν˜ΈμΆœμ„ Python μ½”λ“œλ‘œ μž‘μ„±ν•©λ‹ˆλ‹€.

### Agent [[agent]]

[[autodoc]] Agent

### CodeAgent [[codeagent]]

[[autodoc]] CodeAgent

### React agents [[react-agents]]

[[autodoc]] ReactAgent

[[autodoc]] ReactJsonAgent

[[autodoc]] ReactCodeAgent

## Tools [[tools]]

### load_tool [[loadtool]]

[[autodoc]] load_tool

### Tool [[tool]]

[[autodoc]] Tool

### Toolbox [[toolbox]]

[[autodoc]] Toolbox

### PipelineTool [[pipelinetool]]

[[autodoc]] PipelineTool

### launch_gradio_demo [[launchgradiodemo]]

[[autodoc]] launch_gradio_demo

### ToolCollection [[toolcollection]]

[[autodoc]] ToolCollection

## μ—”μ§„ [[engines]]

μ—μ΄μ „νŠΈ ν”„λ ˆμž„μ›Œν¬μ—μ„œ μ‚¬μš©ν•  수 μžˆλŠ” 엔진을 자유둭게 λ§Œλ“€κ³  μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
이 엔진듀은 λ‹€μŒκ³Ό 같은 사양을 κ°€μ§€κ³  μžˆμŠ΅λ‹ˆλ‹€:
1. μž…λ ₯(`List[Dict[str, str]]`)에 λŒ€ν•œ [λ©”μ‹œμ§€ ν˜•μ‹](../chat_templating.md)을 λ”°λ₯΄κ³  λ¬Έμžμ—΄μ„ λ°˜ν™˜ν•΄μ•Ό ν•©λ‹ˆλ‹€.
2. 인수 `stop_sequences`에 μ‹œν€€μŠ€κ°€ μ „λ‹¬λ˜κΈ° *전에* 좜λ ₯을 μƒμ„±ν•˜λŠ” 것을 쀑지해야 ν•©λ‹ˆλ‹€.

### HfApiEngine [[HfApiEngine]]

편의λ₯Ό μœ„ν•΄, μœ„μ˜ 사항을 κ΅¬ν˜„ν•˜κ³  λŒ€κ·œλͺ¨ μ–Έμ–΄ λͺ¨λΈ 싀행을 μœ„ν•΄ μΆ”λ‘  μ—”λ“œν¬μΈνŠΈλ₯Ό μ‚¬μš©ν•˜λŠ” `HfApiEngine`을 μΆ”κ°€ν–ˆμŠ΅λ‹ˆλ‹€.

```python
>>> from transformers import HfApiEngine

>>> messages = [
...   {"role": "user", "content": "Hello, how are you?"},
...   {"role": "assistant", "content": "I'm doing great. How can I help you today?"},
...   {"role": "user", "content": "No need to help, take it easy."},
... ]

>>> HfApiEngine()(messages, stop_sequences=["conversation"])

"That's very kind of you to say! It's always nice to have a relaxed "
```

[[autodoc]] HfApiEngine


## μ—μ΄μ „νŠΈ μœ ν˜• [[agent-types]]

μ—μ΄μ „νŠΈλŠ” 도ꡬ κ°„μ˜ λͺ¨λ“  μœ ν˜•μ˜ 객체λ₯Ό μ²˜λ¦¬ν•  수 μžˆμŠ΅λ‹ˆλ‹€; λ„κ΅¬λŠ” μ™„μ „νžˆ λ©€ν‹°λͺ¨λ‹¬μ΄λ―€λ‘œ ν…μŠ€νŠΈ, 이미지, μ˜€λ””μ˜€, λΉ„λ””μ˜€ λ“± λ‹€μ–‘ν•œ μœ ν˜•μ„ μˆ˜λ½ν•˜κ³  λ°˜ν™˜ν•  수 μžˆμŠ΅λ‹ˆλ‹€. 
도ꡬ κ°„μ˜ ν˜Έν™˜μ„±μ„ 높이고 ipython (jupyter, colab, ipython λ…ΈνŠΈλΆ, ...)μ—μ„œ μ΄λŸ¬ν•œ 
λ°˜ν™˜ 값을 μ˜¬λ°”λ₯΄κ²Œ λ Œλ”λ§ν•˜κΈ° μœ„ν•΄ μ΄λŸ¬ν•œ μœ ν˜•μ„ μ€‘μ‹¬μœΌλ‘œ 래퍼 클래슀λ₯Ό 
κ΅¬ν˜„ν•©λ‹ˆλ‹€.

λž˜ν•‘λœ κ°μ²΄λŠ” 처음과 λ™μΌν•˜κ²Œ μž‘λ™ν•΄μ•Ό ν•©λ‹ˆλ‹€; ν…μŠ€νŠΈ κ°μ²΄λŠ” μ—¬μ „νžˆ λ¬Έμžμ—΄λ‘œ μž‘λ™ν•΄μ•Ό ν•˜λ©°, 
이미지 κ°μ²΄λŠ” μ—¬μ „νžˆ `PIL.Image`둜 μž‘λ™ν•΄μ•Ό ν•©λ‹ˆλ‹€.

μ΄λŸ¬ν•œ μœ ν˜•μ—λŠ” μ„Έ κ°€μ§€ νŠΉμ • λͺ©μ μ΄ μžˆμŠ΅λ‹ˆλ‹€:

- `to_raw`λ₯Ό ν˜ΈμΆœν•˜λ©΄ κΈ°λ³Έ 객체가 λ°˜ν™˜λ˜μ–΄μ•Ό ν•©λ‹ˆλ‹€.
- `to_string`을 ν˜ΈμΆœν•˜λ©΄ 객체가 λ¬Έμžμ—΄λ‘œ λ°˜ν™˜λ˜μ–΄μ•Ό ν•©λ‹ˆλ‹€: 
`AgentText`의 경우 λ¬Έμžμ—΄μ΄ 될 수 μžˆμ§€λ§Œ, λ‹€λ₯Έ κ²½μš°μ—λŠ” 객체의 μ§λ ¬ν™”λœ λ²„μ „μ˜ 경둜일 수 μžˆμŠ΅λ‹ˆλ‹€.
- ipython μ»€λ„μ—μ„œ ν‘œμ‹œν•  λ•Œ 객체가 μ˜¬λ°”λ₯΄κ²Œ ν‘œμ‹œλ˜μ–΄μ•Ό ν•©λ‹ˆλ‹€.

### AgentText [[agenttext]]

[[autodoc]] transformers.agents.agent_types.AgentText

### AgentImage [[agentimage]]

[[autodoc]] transformers.agents.agent_types.AgentImage

### AgentAudio [[agentaudio]]

[[autodoc]] transformers.agents.agent_types.AgentAudio