added markdown as output format

pull/625/head
Occupying-Mars 5 months ago
parent e9818dbbe0
commit 2aa3bb6538

@ -302,6 +302,7 @@ We provide vast array of features to save agent states using json, yaml, toml, u
| `get_docs_from_doc_folders()` | Fetches all the documents from the doc folders. |
| `activate_agentops()` | Activates agent operations. |
| `check_end_session_agentops()` | Checks the end of the session for agent operations. |
| `model_dump_markdown()` | Dumps the model output to a markdown file. |
@ -544,7 +545,7 @@ Steps:
For example, here's an example on how to create an agent from griptape.
Heres how you can create a custom **Griptape** agent that integrates with the **Swarms** framework by inheriting from the `Agent` class in **Swarms** and overriding the `run(task: str) -> str` method.
Here's how you can create a custom **Griptape** agent that integrates with the **Swarms** framework by inheriting from the `Agent` class in **Swarms** and overriding the `run(task: str) -> str` method.
```python
@ -1857,7 +1858,7 @@ Documentation is located here at: [docs.swarms.world](https://docs.swarms.world)
-----
## Folder Structure
The swarms package has been meticlously crafted for extreme use-ability and understanding, the swarms package is split up into various modules such as `swarms.agents` that holds pre-built agents, `swarms.structs` that holds a vast array of structures like `Agent` and multi agent structures. The 3 most important are `structs`, `models`, and `agents`.
The swarms package has been meticlously crafted for extreme use-ability and understanding, the swarms package is split up into various modules such as `swarms.agents` that holds pre-built agents, `swarms.structs` that holds a vast array of structures like `Agent` and multi agent structures. The 3 most important are `structs`, `models`, and `agents`.
```sh
├── __init__.py

@ -2001,8 +2001,97 @@ class Agent:
model = YamlModel()
return model.dict_to_yaml(self.agent_output.model_dump())
elif self.output_type == "markdown":
# Convert the responses to markdown format
markdown_output = "# Agent Output\n\n"
markdown_output += f"## Agent: {self.agent_name}\n\n"
markdown_output += "### Responses:\n\n"
for i, response in enumerate(responses, 1):
markdown_output += f"{i}. {response}\n\n"
return markdown_output
elif self.output_type == "dict":
return self.agent_output.model_dump()
elif self.return_history:
return self.short_memory.return_history_as_string()
def to_markdown(self) -> str:
"""Convert agent output to markdown format
Returns:
str: Markdown formatted string of agent output
"""
markdown = []
# Add agent name as title
markdown.append(f"# {self.agent_name}\n")
# Add metadata section
markdown.append("## Metadata\n")
markdown.append(f"- **Created**: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
markdown.append(f"- **Max Loops**: {self.max_loops}")
markdown.append(f"- **Autosave**: {self.autosave}")
markdown.append("")
# Add system prompt if exists
if self.system_prompt:
markdown.append("## System Prompt\n")
markdown.append(f"{self.system_prompt}\n")
# Add agent output
if hasattr(self, 'agent_output'):
markdown.append("## Output\n")
if isinstance(self.agent_output, list):
for i, output in enumerate(self.agent_output, 1):
markdown.append(f"{i}. {output}\n")
else:
markdown.append(f"{self.agent_output}\n")
# Add conversation history if exists
if self.short_memory and self.short_memory.messages:
markdown.append("## Conversation History\n")
for msg in self.short_memory.messages:
markdown.append(f"### {msg.role.title()}")
markdown.append(f"{msg.content}\n")
# Add tools section if tools exist
if hasattr(self, 'tools') and self.tools:
markdown.append("## Tools Used\n")
for tool in self.tools:
markdown.append(f"- {tool.__class__.__name__}")
markdown.append("")
return "\n".join(markdown)
def model_dump_markdown(self) -> str:
"""Save the agent output as a markdown file
Returns:
str: Path to saved markdown file
"""
try:
# Generate filename with timestamp
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"{self.agent_name}_{timestamp}.md"
logger.info(
f"Saving {self.agent_name} model to Markdown in the {self.workspace_dir} directory"
)
# Create markdown content
markdown_content = self.to_markdown()
# Save to file
create_file_in_folder(
self.workspace_dir,
filename,
markdown_content,
)
logger.success(f"Successfully saved markdown to {filename}")
return f"Model saved to {self.workspace_dir}/{filename}"
except Exception as e:
logger.error(f"Error saving markdown: {str(e)}")
raise

@ -443,6 +443,8 @@ class BaseTool(BaseModel):
)
# # Example function definitions and mappings
# def get_current_weather(location, unit='celsius'):
# return f"Weather in {location} is likely sunny and 75° {unit.title()}"

Loading…
Cancel
Save