|
1 | | -from swarms import Agent |
2 | | -from swarms.prompts.finance_agent_sys_prompt import ( |
3 | | - FINANCIAL_AGENT_SYS_PROMPT, |
4 | | -) |
5 | | -from swarms.structs.majority_voting import MajorityVoting |
6 | | -from dotenv import load_dotenv |
7 | | - |
8 | | -def streaming_callback(agent_name: str, chunk: str, is_final: bool): |
9 | | - # Chunk buffer static per call (reset each session) |
10 | | - if not hasattr(streaming_callback, "_buffer"): |
11 | | - streaming_callback._buffer = "" |
12 | | - streaming_callback._buffer_size = 0 |
13 | | - |
14 | | - min_chunk_size = 512 # or any large chunk size you want |
15 | | - |
16 | | - if chunk: |
17 | | - streaming_callback._buffer += chunk |
18 | | - streaming_callback._buffer_size += len(chunk) |
19 | | - if streaming_callback._buffer_size >= min_chunk_size or is_final: |
20 | | - if streaming_callback._buffer: |
21 | | - print(streaming_callback._buffer, end="", flush=True) |
22 | | - streaming_callback._buffer = "" |
23 | | - streaming_callback._buffer_size = 0 |
24 | | - if is_final: |
25 | | - print() |
26 | | - |
27 | | -load_dotenv() |
28 | | - |
29 | | - |
30 | | -# Initialize the agent |
31 | | -agent = Agent( |
32 | | - agent_name="Financial-Analysis-Agent", |
33 | | - agent_description="Personal finance advisor agent", |
34 | | - system_prompt=FINANCIAL_AGENT_SYS_PROMPT, |
35 | | - max_loops=1, |
36 | | - model_name="gpt-4.1", |
37 | | - dynamic_temperature_enabled=True, |
38 | | - user_name="swarms_corp", |
39 | | - retry_attempts=3, |
40 | | - context_length=8192, |
41 | | - return_step_meta=False, |
42 | | - output_type="str", # "json", "dict", "csv" OR "string" "yaml" and |
43 | | - auto_generate_prompt=False, # Auto generate prompt for the agent based on name, description, and system prompt, task |
44 | | - max_tokens=4000, # max output tokens |
45 | | - saved_state_path="agent_00.json", |
46 | | - interactive=False, |
47 | | - streaming_on=True, #if concurrent agents want to be streamed |
48 | | -) |
49 | | - |
50 | | -swarm = MajorityVoting(agents=[agent, agent, agent]) |
51 | | - |
52 | | -swarm.run( |
53 | | - "Create a table of super high growth opportunities for AI. I have $40k to invest in ETFs, index funds, and more. Please create a table in markdown.", |
54 | | - streaming_callback=streaming_callback, |
55 | | - |
56 | | -) |
57 | 1 |
|
0 commit comments