samuelemarro commited on
Commit
b6de115
·
1 Parent(s): e057da0

Improved UI and added links.

Browse files
Files changed (1) hide show
  1. app.py +50 -18
app.py CHANGED
@@ -38,12 +38,14 @@ def parse_raw_messages(messages_raw):
38
 
39
  def main():
40
  with gr.Blocks() as demo:
41
- gr.Markdown("# Agora Demo")
42
- gr.Markdown("We will create a new Agora channel and offer it to Alice as a tool.")
 
 
43
 
44
  chosen_task = gr.Dropdown(choices=[
45
  (v['display_name'], k) for k, v in SCHEMAS.items()
46
- ], label="Schema", value="weather_forecast")
47
 
48
  @gr.render(inputs=[chosen_task])
49
  def render2(chosen_task):
@@ -67,10 +69,17 @@ def main():
67
  gr.Markdown('#### Custom Demo Parameters')
68
  gr.Markdown('You can override the default parameters for the demo. Note: recommended for advanced users only.')
69
  gr.Text(label="Description", value=STATE_TRACKER["description"], interactive=True).change(lambda x: STATE_TRACKER.update({'description': x}))
70
- gr.TextArea(label="Input Schema", value=STATE_TRACKER["input"], interactive=True).change(lambda x: STATE_TRACKER.update({'input': x}))
71
- gr.TextArea(label="Output Schema", value=STATE_TRACKER["output"], interactive=True).change(lambda x: STATE_TRACKER.update({'output': x}))
72
- gr.TextArea(label="Tools", value=STATE_TRACKER["tools"], interactive=True).change(lambda x: STATE_TRACKER.update({'tools': x}))
73
- gr.TextArea(label="Examples", value=STATE_TRACKER["examples"], interactive=True).change(lambda x: STATE_TRACKER.update({'examples': x}))
 
 
 
 
 
 
 
74
 
75
  model_options = [
76
  ('GPT 4o (Camel AI)', 'gpt-4o'),
@@ -96,7 +105,7 @@ def main():
96
  with gr.Column(scale=1):
97
  alice_model_dd = gr.Dropdown(label="Alice Model", choices=model_options, value="gpt-4o")
98
  with gr.Column(scale=1):
99
- bob_model_dd = gr.Dropdown(label="Bob Model", choices=model_options, value="gpt-4o")
100
 
101
 
102
 
@@ -104,6 +113,8 @@ def main():
104
  def render_with_images(alice_model, bob_model):
105
  button = gr.Button('Start', elem_id='start_button')
106
  gr.Markdown('## Natural Language')
 
 
107
 
108
  avatar_images = [images.get(alice_model, fallback_image), images.get(bob_model, fallback_image)]
109
  chatbot_nl = gr.Chatbot(type="messages", avatar_images=avatar_images)
@@ -112,13 +123,18 @@ def main():
112
  chatbot_nl_raw = gr.Chatbot(type="messages", avatar_images=avatar_images)
113
 
114
  gr.Markdown('## Negotiation')
 
115
  chatbot_negotiation = gr.Chatbot(type="messages", avatar_images=avatar_images)
116
 
117
  gr.Markdown('## Protocol')
 
 
118
  protocol_hash_result = gr.Text(interactive=False, label="Protocol Hash")
119
  protocol_result = gr.TextArea(interactive=False, label="Protocol")
120
 
121
  gr.Markdown('## Implementation')
 
 
122
  with gr.Row():
123
  with gr.Column(scale=1):
124
  alice_implementation = gr.TextArea(interactive=False, label="Alice Implementation")
@@ -126,18 +142,26 @@ def main():
126
  bob_implementation = gr.TextArea(interactive=False, label="Bob Implementation")
127
 
128
  gr.Markdown('## Structured Communication')
 
129
  structured_communication = gr.Chatbot(type="messages", avatar_images=avatar_images)
130
 
131
  with gr.Accordion(label="Raw Messages", open=False):
132
  structured_communication_raw = gr.Chatbot(type="messages", avatar_images=avatar_images)
133
 
134
  gr.Markdown('## Cost')
 
 
 
135
  cost_info = gr.State(value=None)
136
  #cost_info = gr.TextArea(interactive=False, label="Cost")
137
 
138
- query_slider = gr.Slider(label="Number of queries", minimum=1, maximum=10_000, step=1, value=50, interactive=True)
139
  cost_display = gr.Markdown('')
140
-
 
 
 
 
141
 
142
  def render_info(query_count, cost_info):
143
  if not cost_info:
@@ -145,18 +169,26 @@ def main():
145
  natural_cost = cost_info['conversation'] * query_count
146
  agora_cost = cost_info['negotiation'] + cost_info['programming']
147
 
148
- cost_message = f'Cost of one natural language conversation: {cost_info["conversation"]:.4f} USD\n\n'
149
- cost_message += f'Cost of negotiating the protocol: {cost_info["negotiation"]:.4f} USD\n\n'
150
- cost_message += f'Cost of implementing the protocol: {cost_info["programming"]:.4f} USD\n\n'
151
- cost_message += f'Cost of {query_count} queries with natural language: {natural_cost:.4f} USD\n\n'
152
- cost_message += f'Cost of {query_count} queries with Agora: {agora_cost:.4f} USD\n\n'
 
 
 
 
 
 
 
 
153
 
154
  if natural_cost < agora_cost:
155
  factor = agora_cost / natural_cost
156
- cost_message += f'Natural language is {factor:.2f}x cheaper than Agora.'
157
  else:
158
  factor = natural_cost / agora_cost
159
- cost_message += f'Agora is {factor:.2f}x cheaper than natural language.'
160
 
161
  return cost_message
162
 
@@ -195,7 +227,7 @@ def main():
195
 
196
  button.click(respond, [chosen_task, custom_task, alice_model_dd, bob_model_dd, query_slider], [button, alice_model_dd, bob_model_dd, cost_info, cost_display, chatbot_nl, chatbot_nl_raw, chatbot_negotiation, structured_communication, structured_communication_raw, protocol_result, protocol_hash_result, alice_implementation, bob_implementation])
197
 
198
- demo.launch()
199
 
200
 
201
  if __name__ == '__main__':
 
38
 
39
  def main():
40
  with gr.Blocks() as demo:
41
+ gr.Markdown("# 🏛️Agora Demo")
42
+ gr.Markdown("[Agora](https://agoraprotocol.org/) is a protocol for efficient communication between heterogeneous agents.")
43
+ gr.Markdown("In short, with Agora very different agents can exchange messages efficiently, even if they've never interacted before.")
44
+ gr.Markdown("This demo shows how Agora solves various tasks through a mix of natural language and structured communication.")
45
 
46
  chosen_task = gr.Dropdown(choices=[
47
  (v['display_name'], k) for k, v in SCHEMAS.items()
48
+ ], label="Choose a Demo", value="weather_forecast")
49
 
50
  @gr.render(inputs=[chosen_task])
51
  def render2(chosen_task):
 
69
  gr.Markdown('#### Custom Demo Parameters')
70
  gr.Markdown('You can override the default parameters for the demo. Note: recommended for advanced users only.')
71
  gr.Text(label="Description", value=STATE_TRACKER["description"], interactive=True).change(lambda x: STATE_TRACKER.update({'description': x}))
72
+
73
+ with gr.Row(equal_height=True):
74
+ with gr.Column(scale=1):
75
+ gr.TextArea(label="Input Schema", value=STATE_TRACKER["input"], interactive=True).change(lambda x: STATE_TRACKER.update({'input': x}))
76
+ with gr.Column(scale=1):
77
+ gr.TextArea(label="Output Schema", value=STATE_TRACKER["output"], interactive=True).change(lambda x: STATE_TRACKER.update({'output': x}))
78
+ with gr.Row(equal_height=True):
79
+ with gr.Column(scale=1):
80
+ gr.TextArea(label="Tools", value=STATE_TRACKER["tools"], interactive=True).change(lambda x: STATE_TRACKER.update({'tools': x}))
81
+ with gr.Column(scale=1):
82
+ gr.TextArea(label="Examples", value=STATE_TRACKER["examples"], interactive=True).change(lambda x: STATE_TRACKER.update({'examples': x}))
83
 
84
  model_options = [
85
  ('GPT 4o (Camel AI)', 'gpt-4o'),
 
105
  with gr.Column(scale=1):
106
  alice_model_dd = gr.Dropdown(label="Alice Model", choices=model_options, value="gpt-4o")
107
  with gr.Column(scale=1):
108
+ bob_model_dd = gr.Dropdown(label="Bob Model", choices=model_options, value="claude-3-5-sonnet-latest")
109
 
110
 
111
 
 
113
  def render_with_images(alice_model, bob_model):
114
  button = gr.Button('Start', elem_id='start_button')
115
  gr.Markdown('## Natural Language')
116
+ gr.Markdown("When Agora operates without a protocol, it uses the LLM to send/receive messages.")
117
+ gr.Markdown("This is particularly useful for rare communications, where establishing a protocol would be superfluous.")
118
 
119
  avatar_images = [images.get(alice_model, fallback_image), images.get(bob_model, fallback_image)]
120
  chatbot_nl = gr.Chatbot(type="messages", avatar_images=avatar_images)
 
123
  chatbot_nl_raw = gr.Chatbot(type="messages", avatar_images=avatar_images)
124
 
125
  gr.Markdown('## Negotiation')
126
+ gr.Markdown("If the agents realize that they have been communicating frequently, they negotiate a protocol.")
127
  chatbot_negotiation = gr.Chatbot(type="messages", avatar_images=avatar_images)
128
 
129
  gr.Markdown('## Protocol')
130
+ gr.Markdown("The agents now have an unambiguous protocol to follow. This reduces redundant communications and mistakes.")
131
+ gr.Markdown("The protocol is stored into a Protocol Document and is uniquely identified by its SHA1 hash.")
132
  protocol_hash_result = gr.Text(interactive=False, label="Protocol Hash")
133
  protocol_result = gr.TextArea(interactive=False, label="Protocol")
134
 
135
  gr.Markdown('## Implementation')
136
+ gr.Markdown("If they desire, Alice and Bob can independently implement their side of the protocol as routines (e.g. Python modules).")
137
+ gr.Markdown("The routines handle the protocol communication without needing to invoke the LLM.")
138
  with gr.Row():
139
  with gr.Column(scale=1):
140
  alice_implementation = gr.TextArea(interactive=False, label="Alice Implementation")
 
142
  bob_implementation = gr.TextArea(interactive=False, label="Bob Implementation")
143
 
144
  gr.Markdown('## Structured Communication')
145
+ gr.Markdown("The agents now communicate using the routines. This is faster, more reliable and cheaper than using the LLM.")
146
  structured_communication = gr.Chatbot(type="messages", avatar_images=avatar_images)
147
 
148
  with gr.Accordion(label="Raw Messages", open=False):
149
  structured_communication_raw = gr.Chatbot(type="messages", avatar_images=avatar_images)
150
 
151
  gr.Markdown('## Cost')
152
+ gr.Markdown("Negotiation & implementation have a higher upfront cost, but once they're done, the cost of using a routine is neglible compared to invoking an LLM.")
153
+ gr.Markdown("This means that, for moderate to high frequency communications, negotiation & implementation with Agora is way cheaper than using natural language alone.")
154
+ gr.Markdown("Note: negotiated protocols can be reused for similar tasks and shared with other agents, which further reduces costs.")
155
  cost_info = gr.State(value=None)
156
  #cost_info = gr.TextArea(interactive=False, label="Cost")
157
 
158
+ query_slider = gr.Slider(label="Expected number of queries", minimum=1, maximum=10_000, step=1, value=50, interactive=True)
159
  cost_display = gr.Markdown('')
160
+
161
+ gr.Markdown('## Next Steps')
162
+ gr.Markdown("This demo showcases a simple negotiation-and-implementation flow between two agents.")
163
+ gr.Markdown("In practice, Agora can be used to build entire networks of agents, with way more complex tasks.")
164
+ gr.Markdown("Also, don't forget us to follow us on [Twitter](https://twitter.com/Agora_Protocol) and join our [Discord](https://discord.gg/MXmfhwQ4FB)!")
165
 
166
  def render_info(query_count, cost_info):
167
  if not cost_info:
 
169
  natural_cost = cost_info['conversation'] * query_count
170
  agora_cost = cost_info['negotiation'] + cost_info['programming']
171
 
172
+ cost_message = ''
173
+ cost_message += f"""
174
+ |Operation|Cost (USD)|
175
+ |---|---|
176
+ |Natural language conversation|{cost_info["conversation"]:.4f}|
177
+ |Negotiation|{cost_info["negotiation"]:.4f}|
178
+ |Programming|{cost_info["programming"]:.4f}|
179
+
180
+ Cost of {query_count} queries:
181
+ - With natural language: {natural_cost:.4f} USD
182
+ - With Agora: {agora_cost:.4f} USD
183
+
184
+ """
185
 
186
  if natural_cost < agora_cost:
187
  factor = agora_cost / natural_cost
188
+ cost_message += f'#### Natural language is {factor:.2f}x cheaper than Agora.'
189
  else:
190
  factor = natural_cost / agora_cost
191
+ cost_message += f'## Agora is {factor:.2f}x cheaper than natural language.'
192
 
193
  return cost_message
194
 
 
227
 
228
  button.click(respond, [chosen_task, custom_task, alice_model_dd, bob_model_dd, query_slider], [button, alice_model_dd, bob_model_dd, cost_info, cost_display, chatbot_nl, chatbot_nl_raw, chatbot_negotiation, structured_communication, structured_communication_raw, protocol_result, protocol_hash_result, alice_implementation, bob_implementation])
229
 
230
+ demo.launch(share=True)
231
 
232
 
233
  if __name__ == '__main__':