Skip to content

Commit ce3bb96

Browse files
committed
bump package version
1 parent 7d5cb5c commit ce3bb96

18 files changed

+179
-109
lines changed
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

examples/streamlit_mcp_basic_agent/main.py

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,54 @@
55
from mcp_agent.agents.agent import Agent
66
from mcp_agent.workflows.llm.augmented_llm import RequestParams
77
from mcp_agent.workflows.llm.augmented_llm_openai import OpenAIAugmentedLLM
8+
from dataclasses import dataclass
9+
from typing import Optional, Type, TypeVar
10+
11+
T = TypeVar("T", bound=OpenAIAugmentedLLM)
12+
13+
14+
@dataclass
15+
class AgentState:
16+
"""Container for agent and its associated LLM"""
17+
18+
agent: Agent
19+
llm: Optional[OpenAIAugmentedLLM] = None
20+
21+
22+
async def get_agent_state(
23+
key: str,
24+
agent_class: Type[Agent],
25+
llm_class: Optional[Type[T]] = None,
26+
**agent_kwargs,
27+
) -> AgentState:
28+
"""
29+
Get or create agent state, reinitializing connections if retrieved from session.
30+
31+
Args:
32+
key: Session state key
33+
agent_class: Agent class to instantiate
34+
llm_class: Optional LLM class to attach
35+
**agent_kwargs: Arguments for agent instantiation
36+
"""
37+
if key not in st.session_state:
38+
# Create new agent
39+
agent = agent_class(
40+
connection_persistence=False,
41+
**agent_kwargs,
42+
)
43+
await agent.initialize()
44+
45+
# Attach LLM if specified
46+
llm = None
47+
if llm_class:
48+
llm = await agent.attach_llm(llm_class)
49+
50+
state: AgentState = AgentState(agent=agent, llm=llm)
51+
st.session_state[key] = state
52+
else:
53+
state = st.session_state[key]
54+
55+
return state
856

957

1058
def format_list_tools_result(list_tools_result: ListToolsResult):
@@ -17,18 +65,20 @@ def format_list_tools_result(list_tools_result: ListToolsResult):
1765
async def main():
1866
await app.initialize()
1967

20-
finder_agent = Agent(
68+
# Use the state management pattern
69+
state = await get_agent_state(
70+
key="finder_agent",
71+
agent_class=Agent,
72+
llm_class=OpenAIAugmentedLLM,
2173
name="finder",
2274
instruction="""You are an agent with access to the filesystem,
2375
as well as the ability to fetch URLs. Your job is to identify
2476
the closest match to a user's request, make the appropriate tool calls,
2577
and return the URI and CONTENTS of the closest match.""",
2678
server_names=["fetch", "filesystem"],
2779
)
28-
await finder_agent.initialize()
29-
llm = await finder_agent.attach_llm(OpenAIAugmentedLLM)
3080

31-
tools = await finder_agent.list_tools()
81+
tools = await state.agent.list_tools()
3282
tools_str = format_list_tools_result(tools)
3383

3484
st.title("💬 Basic Agent Chatbot")
@@ -53,8 +103,17 @@ async def main():
53103
with st.chat_message("assistant"):
54104
response = ""
55105
with st.spinner("Thinking..."):
56-
response = await llm.generate_str(
57-
message=prompt, request_params=RequestParams(use_history=True)
106+
# Pass the conversation history to the LLM
107+
conversation_history = st.session_state["messages"][
108+
1:
109+
] # Skip the initial greeting
110+
111+
response = await state.llm.generate_str(
112+
message=prompt,
113+
request_params=RequestParams(
114+
use_history=True,
115+
history=conversation_history, # Pass the conversation history
116+
),
58117
)
59118
st.markdown(response)
60119

Lines changed: 112 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,112 @@
1-
# Graded Report: Evaluation of "The Battle of Glimmerwood"
2-
3-
This report consolidates feedback on the short story in three key areas: proofreading, factual/logical consistency, and APA style adherence. The goal is to offer actionable recommendations to improve both the narrative clarity and its academic presentation.
4-
5-
---
6-
7-
## 1. Proofreading Feedback
8-
9-
The text contains several typographical, grammatical, and punctuation issues. Key points include:
10-
11-
- **Spelling Errors:**
12-
- *"knowed"* should be replaced by *"known"*.
13-
- *"choas"* should be corrected to *"chaos"*.
14-
- *"shaterred"* should be changed to *"shattered"*.
15-
- *"aproached"* should be corrected to *"approached"*.
16-
17-
- **Grammatical Inconsistencies:**
18-
- Phrases like *"who were live peacefully"* need revision to *"who lived peacefully"*.
19-
- Some verb tenses and subject-verb agreements are inconsistent (e.g., *"aim"* vs. *"aimed"*; *"captured"* instead of *"capture"*).
20-
21-
- **Punctuation Issues:**
22-
- Comma splices in sentences (e.g., joining two independent clauses with only a comma) should be revised using semicolons or by splitting into separate sentences.
23-
- Missing commas after introductory phrases and before non-restrictive clauses reduce clarity.
24-
25-
Addressing these issues will enhance readability and ensure the narrative is polished.
26-
27-
---
28-
29-
## 2. Fact-Checking and Logical Consistency
30-
31-
The story is set within a fantasy framework and largely maintains internal consistency. Notable points include:
32-
33-
- **Consistency with the Genre:**
34-
- The narrative establishes a mystical setting (Glimmerwood) with magical creatures and powerful artifacts (Glimmerstones) that fit within the fantasy genre.
35-
36-
- **Ambiguity in Plot Elements:**
37-
- The true power of the Glimmerstones is left ambiguous (stated as never being fully confirmed), which could be a deliberate narrative device but may confuse readers if not further clarified.
38-
- The rapid resolution of conflict—such as the sudden appearance of magical defenses—could be enhanced by providing more background on the villagers’ relationship with these creatures.
39-
40-
Overall, while the internal logic is maintained, clarifying these ambiguities could strengthen the narrative coherence.
41-
42-
---
43-
44-
## 3. APA Style and Formatting Evaluation
45-
46-
The document in its current Markdown format does not adhere to APA formatting guidelines. Key considerations include:
47-
48-
- **Title Page and Running Head:**
49-
- APA style requires a separate title page with centered title, author information, institutional affiliation, and a running head with page numbers. The narrative presently uses a markdown header instead.
50-
51-
- **Headings and Text Formatting:**
52-
- APA requires a specific hierarchy for headings. Replace Markdown-style headers with APA-compliant formatting (e.g., centered, bold, and appropriately leveled headings).
53-
- Use 12-point Times New Roman font, double spacing, and 1-inch margins throughout the document.
54-
55-
- **References and Citations:**
56-
- If external sources are cited, they must be formatted with hanging indents and correct capitalization. Although the narrative does not include citations, any future references should comply with APA guidelines.
57-
58-
Adopting these APA standards will ensure the document meets academic requirements and appears professionally formatted.
59-
60-
---
61-
62-
## 4. Overall Recommendations
63-
64-
While "The Battle of Glimmerwood" is imaginative and engaging, consider the following actions to further refine the work:
65-
66-
- **Proofreading:** Address the identified spelling, grammar, and punctuation errors to improve clarity and professionalism.
67-
- **Narrative Clarity:** Provide additional context for certain fantasy elements (e.g., the nature of the Glimmerstones and the villagers’ relationship with magical creatures) to bolster logical consistency.
68-
- **APA Formatting:** Transition the document from Markdown to an APA-compliant format by creating a proper title page, adjusting heading styles, and ensuring standard text formatting (12-point Times New Roman, double spacing, 1-inch margins).
69-
70-
Implementing these revisions will enhance both the readability and academic rigor of the work.
71-
72-
---
73-
74-
*End of Report*
75-
76-
---
77-
78-
## Final Consolidation and Objective Completion
79-
80-
Based on the analysis across proofreading, factual/logical consistency, and APA style adherence, all criteria have been met. Minor enhancements, such as adding a dedicated fact-checking section, have been recommended, but these do not impede the overall completion of the objective.
81-
82-
Objective Status: Complete.
1+
# Graded Report for 'The Battle of Glimmerwood'
2+
3+
## Proofreading Feedback
4+
5+
**Corrections and Feedback:**
6+
7+
1. **Sentence 1:**
8+
- Original: "In the heart of Glimmerwood, a mystical forest knowed for its radiant trees, a small village thrived."
9+
- Correction: Change "knowed" to “known.”
10+
- Revised: "In the heart of Glimmerwood, a mystical forest known for its radiant trees, a small village thrived."
11+
12+
2. **Sentence 2:**
13+
- Original: "The villagers, who were live peacefully, shared their home with the forest's magical creatures, especially the Glimmerfoxes whose fur shimmer like moonlight."
14+
- Corrections:
15+
- Change “were live” to "lived."
16+
- Change "shimmer" to "shimmered."
17+
- Add a comma after "Glimmerfoxes."
18+
- Revised: "The villagers, who lived peacefully, shared their home with the forest's magical creatures, especially the Glimmerfoxes, whose fur shimmered like moonlight."
19+
20+
3. **Sentence 3:**
21+
- Original: "One fateful evening, the peace was shaterred when the infamous Dark Marauders attack."
22+
- Corrections:
23+
- Change "shaterred" to "shattered."
24+
- Change "attack" to "attacked."
25+
- Revised: "One fateful evening, the peace was shattered when the infamous Dark Marauders attacked."
26+
27+
4. **Sentence 4:**
28+
- Original: "Lead by the cunning Captain Thorn, the bandits aim to steal the precious Glimmerstones which was believed to grant immortality."
29+
- Corrections:
30+
- Change "Lead" to "Led."
31+
- Change "aim" to "aimed."
32+
- Change "was" to "were."
33+
- Add a comma after "Glimmerstones."
34+
- Revised: "Led by the cunning Captain Thorn, the bandits aimed to steal the precious Glimmerstones, which were believed to grant immortality."
35+
36+
5. **Sentence 5:**
37+
- Original: "Amidst the choas, a young girl named Elara stood her ground, she rallied the villagers and devised a clever plan."
38+
- Corrections:
39+
- Correct the spelling from "choas" to "chaos."
40+
- Consider separating into two sentences for clarity.
41+
- Add a comma after "villagers."
42+
- Revised: "Amidst the chaos, a young girl named Elara stood her ground. She rallied the villagers and devised a clever plan."
43+
44+
6. **Sentence 6:**
45+
- Original: "Using the forests natural defenses they lured the marauders into a trap."
46+
- Correction: Add an apostrophe to "forests" to make it possessive.
47+
- Revised: "Using the forest's natural defenses, they lured the marauders into a trap."
48+
49+
7. **Sentence 7:**
50+
- Original: "As the bandits aproached the village square, a herd of Glimmerfoxes emerged, blinding them with their dazzling light, the villagers seized the opportunity to captured the invaders."
51+
- Corrections:
52+
- Correct the spelling from "aproached" to "approached."
53+
- Consider separating into two sentences for clarity.
54+
- Change "captured" to "capture."
55+
- Revised: "As the bandits approached the village square, a herd of Glimmerfoxes emerged, blinding them with their dazzling light. The villagers seized the opportunity to capture the invaders."
56+
57+
8. **Sentence 8:**
58+
- Original: "Elara's bravery was celebrated and she was hailed as the 'Guardian of Glimmerwood'."
59+
- Correction: Add a comma after "celebrated."
60+
- Revised: "Elara's bravery was celebrated, and she was hailed as the 'Guardian of Glimmerwood.'"
61+
62+
9. **Sentence 9:**
63+
- Original: "The Glimmerstones were secured in a hidden grove protected by an ancient spell."
64+
- Feedback: This sentence is grammatically correct.
65+
66+
10. **Sentence 10:**
67+
- Original: "However, not all was as it seemed. The Glimmerstones true power was never confirm, and whispers of a hidden agenda linger among the villagers."
68+
- Corrections:
69+
- Add an apostrophe to "Glimmerstones" to make it possessive.
70+
- Change "confirm" to "confirmed."
71+
- Change "linger" to "lingered."
72+
- Revised: "However, not all was as it seemed. The Glimmerstones' true power was never confirmed, and whispers of a hidden agenda lingered among the villagers."
73+
74+
## Factuality and Logical Consistency
75+
76+
1. **Setting Description:**
77+
- The story effectively describes Glimmerwood, a mystical forest known for its radiant trees, setting a consistent fantasy tone with magical creatures like Glimmerfoxes.
78+
79+
2. **Character and Plot Consistency:**
80+
- The scenario with Elara rallying the villagers against the Dark Marauders aligns with common fantasy hero themes.
81+
- The belief in Glimmerstones granting immortality is inconsistent with the unresolved mystery of their true power, suggesting a need for earlier acknowledgment.
82+
- The forest's defenses and Glimmerfoxes' role in trapping marauders is plausible within the fantasy context, showcasing Elara’s bravery and cleverness.
83+
84+
3. **Logical Inconsistencies:**
85+
- The transition between invasion and resolution is abrupt; more detail would fortify understanding of the trap setup.
86+
- The mention of a "hidden agenda" requires clarification if pivotal to the plot.
87+
88+
## Adherence to APA Style Guidelines
89+
90+
1. **Title and Headings:**
91+
- Ensure the title "The Battle of Glimmerwood" appears centered and bolded.
92+
93+
2. **Font and Spacing:**
94+
- Consistent use of a 12-point Times New Roman font with double spacing.
95+
96+
3. **Margins:**
97+
- Standard 1-inch margins should be present on all sides.
98+
99+
4. **Grammar and Clarity:**
100+
- Improvements made by correcting grammar errors like "knowed" to "known" and resolving run-on sentences for clarity.
101+
- Proper past tense usage enforced for verbs such as "attack" to "attacked."
102+
103+
5. **Tone and Engagement:**
104+
- A formal but narrative tone is maintained while using engaging language to enhance plot and characters in adherence to style.
105+
106+
### Suggestions for Enhancement:
107+
108+
- **Character Development:** Additional background or internal dialogues for characters like Elara can heighten reader engagement.
109+
- **Descriptive Language:** Employing vivid descriptions for mystical elements enhances immersion.
110+
- **Conflict Resolution:** Detailed explanation of invasion repulsion strategies provides satisfying conflict resolution.
111+
112+
The feedback provided aims to refine the overall storytelling experience while ensuring adherence to APA formatting standards where applicable.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "mcp-agent"
3-
version = "0.0.14"
3+
version = "0.0.15"
44
description = "Build effective agents with Model Context Protocol (MCP) using simple, composable patterns."
55
readme = "README.md"
66
license = { file = "LICENSE" }

uv.lock

Lines changed: 1 addition & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)