Skip to content

Commit f699ccd

Browse files
Updates for initial release (#36)
Update docs and scripts
1 parent 81f3cd8 commit f699ccd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+708
-467
lines changed

CONVENTIONS.md

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
11
# General code standards
22

3+
Do not update project level configuration files unless explicitly instructed to.
4+
35
Use async/await where possible
46

57
Test exceptional cases first and return/throw early.
68

7-
# Test code standards
8-
9-
Unit test files should be in the same directory as the source file.
10-
11-
Any usage of chai-as-promised should use async/await
12-
```
13-
it('should work well with async/await', async () => {
14-
(await Promise.resolve(42)).should.equal(42)
15-
await Promise.reject(new Error()).should.be.rejectedWith(Error);
16-
});
17-
```
18-
19-
# Tool/function classes
20-
21-
Function classes with the @funcClass(__filename) must only have the default constructor.
22-
23-
Always use the Filesystem class in src/functions/storage/filesystem.ts to read/search/write to the local filesystem.

Dockerfile.dev

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ RUN curl -sL https://deb.nodesource.com/setup_20.x -o nodesource_setup.sh
99
RUN chmod +x ./nodesource_setup.sh && ./nodesource_setup.sh
1010
RUN apt install -y nodejs
1111

12-
RUN npm install -g pm2
13-
1412
RUN pip install aider-chat
1513

1614
ENV user=sophia
1715
ENV homedir=/home/sophia/
1816
RUN useradd --create-home -g users sophia
17+
1918
WORKDIR $homedir
2019

2120
RUN mkdir ".husky"
@@ -24,8 +23,6 @@ COPY .husky/install.mjs .husky/install.mjs
2423
COPY package*.json ./
2524
RUN npm install
2625

27-
COPY . .
28-
2926
# Install Angular dependencies and build Angular app
3027
WORKDIR $homedir/frontend
3128
COPY frontend/package*.json ./
@@ -39,8 +36,8 @@ USER $user
3936

4037
ENV NODE_ENV=production
4138

42-
# In the frontend package.jsson the `ng serve` needs the arg --host 0.0.0.0 for it to be available from the host machine
39+
# In the frontend package.json the `ng serve` needs the arg --host 0.0.0.0 for it to be available from the host machine
4340
EXPOSE 4200
4441
EXPOSE 3000
45-
CMD ["pm2-runtime", "start", "resources/ecosystem.config.js"]
42+
CMD ["./bin/cmd-script"]
4643

README.md

Lines changed: 101 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,131 @@
11
<a id="banner"></a>
22
<p align="center">
3-
<img src="https://public.trafficguard.ai/sophia/banner.png" alt="nous logo"/>
3+
<img src="https://public.trafficguard.ai/sophia/banner.png" alt="Sophia banner"/>
44
</p>
55
<p align="center">
6-
<em>The open-source TypeScript platform for autonomous AI agents and LLM based workflows </em>
6+
<em>The open TypeScript platform for autonomous AI agents and LLM based workflows </em><br/>
7+
<small>The Ancient Greek word <em><b>sophía (σοφία)</b></em> variously translates to "clever, skillful, intelligent, wise"</small>
78
</p>
8-
The Ancient Greek word <em><b>sophía (σοφία)</b></em> is the abstract noun of σοφός (sophós), which variously translates to "clever, skillful, intelligent, wise"
99

1010
## Documentation site
1111
[Home](https://sophia.dev/) | [Setup](https://sophia.dev/setup/) | [Observability](https://sophia.dev/observability/) | [Function calling](https://sophia.dev/functions/) |
12-
[Autonomous AI Agent](https://sophia.dev/xml-agent/) | [AI Software Engineer](https://sophia.dev/software-engineer/) | [AI Code reviews](https://sophia.dev/code-review/) |
12+
[Autonomous AI Agent](https://sophia.dev/autonomous-agents/) | [AI Software Engineer](https://sophia.dev/software-engineer/) | [AI Code reviews](https://sophia.dev/code-review/) |
1313
[Tools/Integrations](https://sophia.dev/integrations/) | [Roadmap](https://sophia.dev/roadmap/)
1414

1515
---
1616

17-
[The Sophia Story](#the-sophia-story) | [Features](#features) | [UI Examples](#ui-examples) | [Code examples](#code-examples) | [Contributing](#contributing)
17+
[Features](#key-features) | [UI Examples](#ui-examples) | [Code examples](#code-examples) | [Contributing](#contributing)
1818

19-
## The Sophia Story
19+
Sophia is a full-featured platform for developing and running agents, LLM based workflows and chatbots.
2020

21-
Sophia started from a simple goal: to harness AI's potential to enhance real-world productivity, born in DevOps and Platform Engineering space. We envisioned a tool that could:
21+
Included are capable software engineering agents, which have assisted building the platform.
2222

23-
- Automate various processes and support requests, and triage build failures.
24-
- Review code for compliance with standards and best practices.
25-
- Assist with large refactorings, and more.
23+
## Key features
2624

27-
At TrafficGuard we process billions of events a month for our global clients, [increasing their ad spend ROI](https://www.trafficguard.ai/case-studies?ref=gh) by protecting against bots and other forms of invalid traffic.
28-
Our SaaS on GCP comprises projects developed in TypeScript, Python, GoogleSQL, PHP and Terraform, deployed from GitLab.
25+
- [Advanced Autonomous agents](https://sophia.dev/autonomous-agents)
26+
- [Software developer agents](https://sophia.dev/software-engineer/)
27+
- [Pull request code review agent](https://sophia.dev/code-review/)
28+
- [AI chat interface](https://sophia.dev/chat/)
29+
- [Slack chatbot](https://sophia.dev/chatbot/)
30+
- Supports many LLM services - OpenAI, Anthropic (native & Vertex), Gemini, Groq, Fireworks, Together.ai, DeepSeek, Ollama, Cerebras, X.ai
31+
- Multi-agent [extend-reasoning implementations](https://github.com/TrafficGuard/sophia/tree/main/src/llm/multi-agent) of the LLM interface
32+
- Configurable Human-in-the-loop settings
33+
- [Functional callable tools/integrations](https://sophia.dev/integrations/) (Filesystem, Jira, Slack, Perplexity, Google Cloud, Gitlab, GitHub etc)
34+
- CLI and Web UI interface
35+
- Run locally or deployed on the cloud with multi-user/SSO
36+
- OpenTelemetry based observability
37+
- Leverages the extensive Python AI ecosystem through executing Python scripts/packages
2938

30-
With open source projects typically Python/GitHub focused, and the vendor AI tools being focused in their silos,
31-
we saw a need for TypeScript based tooling which can work across our entire tech stack, and understand the overall architecture.
39+
## Autonomous agents
3240

33-
Through its evolution we've designed sophia as a flexible platform for the TypeScript community to expand and support the use cases and integrations of your choice.
34-
35-
Our design choice of Firestore for the initial database implementation, with Cloud Run, provides a scale-to-zero solution with zero-cost using the free tier.
36-
With the intention to support uses cases such as your own custom personal assistant, always available via mobile.
41+
- Reasoning/planning inspired from Google's [Self-Discover](https://arxiv.org/abs/2402.03620) and other papers
42+
- Memory and function call history for complex workflows
43+
- Iterative planning with hierarchical task decomposition
44+
- Sandboxed execution of generated code for multi-step function calling and logic
45+
- LLM function schemas auto-generated from source code
46+
- Human-in-the-loop for budget control, agent initiated questions and error handling
3747

38-
## Features
48+
More details at the [Autonomous agent docs](https://sophia.dev/autonomous-agents)
3949

40-
Key features include:
50+
## Software developer agents
4151

42-
- Advanced autonomous agents
43-
- Reasoning/planning inspired from Google's [Self-Discover](https://arxiv.org/abs/2402.03620) paper
44-
- Memory and function call history for complex, multi-step workflows
45-
- Adaptive iterative planning with hierarchical task decomposition
46-
- Two control-loop function calling options (LLM-independent):
47-
- Custom XML-based function calling
48-
- Dynamic code generation with sandboxed execution for multistep function calling and logic
49-
- Opportunistically can significantly reduce cost and latency over LLM-native/XML function calling
50-
- LLM function schemas auto-generated from source code
51-
- Function callable integrations:
52-
- Filesystem, Jira, Slack, Perplexity, Gitlab, GitHub and more
53-
- Supports multiple LLMs/Services:
54-
- OpenAI, Anthropic (native & Vertex), Gemini, Groq, Fireworks, Together.ai, DeepSeek, Ollama, Cerebras, X.ai
55-
- CLI and Web interface
56-
- Human-in-the-loop for:
57-
- Budget control
58-
- Agent initiated questions
59-
- Error handling
60-
- Flexible deployment options:
61-
- Run locally from the command line or through the web UI
62-
- Scale-to-zero deployment on Firestore & Cloud Run
63-
- Multi-user SSO enterprise deployment (with [Google Cloud IAP](https://cloud.google.com/security/products/iap))
64-
- Observability with OpenTelemetry tracing
65-
- Code Editing Agent:
52+
- Code Editing Agent for local repositories
6653
- Auto-detection of project initialization, compile, test and lint
67-
- Find the relevant files to edit and perform initial analysis
54+
- Task file selection agent selects the relevant files
55+
- Design agent creates the implementation plan.
6856
- Code editing loop with compile, lint, test, fix (editing delegates to [Aider](https://aider.chat/))
6957
- Compile error analyser can search online, add additional files and packages
70-
- Software Engineer Agent:
58+
- Final review of the changes with an additional code editing loop if required.
59+
- Software Engineer Agent (For ticket to Pull Request workflow):
7160
- Find the appropriate repository from GitLab/GitHub
7261
- Clone and create branch
7362
- Call the Code Editing Agent
7463
- Create merge request
7564
- Code Review agent:
7665
- Configurable code review guidelines
7766
- Posts comments on GitLab merge requests at the appropriate line with suggested changes
67+
- Repository ad hoc query agent
68+
- Codebase awareness - optional index creation used by the task file selection agent
69+
70+
More details at the [Software developer agents](https://sophia.dev/software-engineer/) docs.
71+
72+
## Flexible run/deploy options
73+
74+
- Run from the repository or the provided Dockerfile in single user mode.
75+
- CLI interface
76+
- Web interface
77+
- Scale-to-zero deployment on Firestore & Cloud Run
78+
- Multi-user SSO enterprise deployment (with [Google Cloud IAP](https://cloud.google.com/security/products/iap))
79+
- Terraform, infra scripts and more authentication options coming soon.
7880

7981
## UI Examples
8082

81-
[New Agent](#new-agent) | [Sample trace](#sample-trace) | [Human in the loop notification](#human-in-the-loop-notification) | [Agent requested feedback](#agent-requested-feedback) | [List agents](#list-agents) | [Code review config](#code-review-configuration)
83+
### List agents
84+
85+
![List agents](https://public.trafficguard.ai/sophia/agent-list.png)
8286

8387
### New Agent
8488

85-
![New Agent UI](https://public.trafficguard.ai/sophia/start.png)
89+
![New Agent UI](https://public.trafficguard.ai/sophia/agent-new.png)
8690

87-
### Sample trace
91+
### Agent error handling
8892

89-
![Sample trace in Google Cloud](https://public.trafficguard.ai/nous/trace.png)
93+
![Feedback requested](https://public.trafficguard.ai/sophia/agent-feedback.png)
9094

91-
### Human in the loop notification
95+
### Agent LLM calls
9296

93-
<img src="https://public.trafficguard.ai/nous/feedback.png" width="702">
97+
![Agent LLM calls](https://public.trafficguard.ai/sophia/agent-llm-calls.png)
9498

95-
### Agent requested feedback
99+
### Sample trace (Google Cloud)
96100

97-
![Feedback requested](https://public.trafficguard.ai/nous/agent-feedback.png)
101+
![Sample trace in Google Cloud](https://public.trafficguard.ai/sophia/trace.png)
98102

99-
### List agents
103+
### Human in the loop notification
100104

101-
![List agents](https://public.trafficguard.ai/nous/list.png)
105+
<img src="https://public.trafficguard.ai/sophia/feedback.png" width="702">
102106

103107
### Code review configuration
104108

105-
![Code review configuration](https://public.trafficguard.ai/nous/code-review.png)
109+
![Code review configuration](https://public.trafficguard.ai/sophia/code-reviews.png)
110+
111+
### AI Chat
112+
113+
![AI chat](https://public.trafficguard.ai/sophia/chat.png)
114+
115+
### User profile
116+
117+
![Profile](https://public.trafficguard.ai/sophia/profile1.png)
118+
![Profile](https://public.trafficguard.ai/sophia/profile2.png)
119+
120+
Default values can also be set from environment variables.
106121

107122
## Code Examples
108123

109124
### Sophia vs LangChain
110125

111-
Sophia doesn't use LangChain, for [many reasons](https://www.octomind.dev/blog/why-we-no-longer-use-langchain-for-building-our-ai-agents) that [you](https://www.google.com/search?q=langchain+site%3Anews.ycombinator.com) can [read online](https://www.google.com/search?q=langchain+sucks+site%3Areddit.com)
126+
Sophia doesn't use LangChain, for [many reasons](https://www.octomind.dev/blog/why-we-no-longer-use-langchain-for-building-our-ai-agents) that [you](https://www.google.com/search?q=langchain+site%3Anews.ycombinator.com) can [read](https://www.reddit.com/r/LangChain/comments/1gmfyi2/why_are_people_hating_langchain_so_much/) [online](https://www.google.com/search?q=langchain+sucks+site%3Areddit.com)
127+
128+
The scope of the Sophia platform covers functionality found in LangChain and LangSmith.
112129

113130
Let's compare the LangChain document example for Multiple Chains to the equivalent Sophia implementation.
114131

@@ -150,17 +167,17 @@ console.log(result);
150167

151168
#### Sophia
152169
```typescript
153-
import { llms } from '#agent/context'
170+
import { runAgentWorkflow } from '#agent/agentWorkflowRunner';
154171
import { anthropicLLMs } from '#llms/anthropic'
155172

156-
const prompt1 = (person: string) => `What is the city ${person} is from? Only respond with the name of the city.`;
157-
const prompt2 = (city: string, language: string) => `What country is the city ${city} in? Respond in ${language}.`;
173+
const cityFromPerson = (person: string) => `What is the city ${person} is from? Only respond with the name of the city.`;
174+
const countryFromCity = (city: string, language: string) => `What country is the city ${city} in? Respond in ${language}.`;
158175

159176
runAgentWorkflow({ llms: anthropicLLMs() }, async () => {
160-
const city = await llms().easy.generateText(prompt1('Obama'));
161-
const result = await llms().easy.generateText(prompt2(city, 'German'));
177+
const city = await llms().easy.generateText(cityFromPerson('Obama'));
178+
const country = await llms().easy.generateText(countryFromCity(city, 'German'));
162179

163-
console.log(result);
180+
console.log(country);
164181
});
165182
```
166183

@@ -180,20 +197,28 @@ startAgent({
180197

181198
### Automated LLM function schemas
182199

183-
LLM function calling schemas are automatically generated by having the `@func` decorator on class methods.
184-
185-
![New Agent UI](https://public.trafficguard.ai/nous/jira-function-def.png)
186-
187-
### Getting Started
200+
LLM function calling schema are automatically generated by having the `@func` decorator on class methods, avoiding the
201+
definition duplication using zod or JSON.
188202

189-
Visit our [documentation site](https://nous.trafficguard.ai/setup/) for the getting started guide and more details.
203+
```typescript
204+
@funcClass(__filename)
205+
export class Jira {
206+
instance: AxiosInstance | undefined;
207+
208+
/**
209+
* Gets the description of a JIRA issue
210+
* @param {string} issueId - the issue id (e.g. XYZ-123)
211+
* @returns {Promise<string>} the issue description
212+
*/
213+
@func()
214+
async getJiraDescription(issueId: string): Promise<string> {
215+
if (!issueId) throw new Error('issueId is required');
216+
const response = await this.axios().get(`issue/${issueId}`);
217+
return response.data.fields.description;
218+
}
219+
}
220+
```
190221

191222
## Contributing
192223

193224
We warmly welcome contributions to the project through [issues](https://github.com/TrafficGuard/nous/issues), [pull requests](https://github.com/TrafficGuard/nous/pulls) or [discussions](https://github.com/TrafficGuard/nous/discussions)
194-
195-
Contributed by [TrafficGuard](https://www.trafficguard.ai) - Increasing the ROI on your ad spend.
196-
197-
Reach out to us as nous@trafficguard.ai if you'd like support to ramp up as a contributor.
198-
199-

bin/aider

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ echo $VERTEXAI_PROJECT $VERTEXAI_LOCATION
77
export OPENAI_API_KEY=$OPENAI_API_KEY
88
export DEEPSEEK_API_KEY=$DEEPSEEK_API_KEY
99

10-
aider --sonnet --architect
10+
aider --architect --o1-preview --editor-model vertex_ai/claude-3-5-sonnet@20240620

bin/cmd-script

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
cd frontend && npm run start:local &
3+
npm run start:local &
4+
wait

bin/configure

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/bin/bash
12

23
# Python setup ---------------------------------
34

bin/container

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
docker exec -it $(docker ps -qf "name=sophia-dev") bash

bin/gcp_setup

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,48 @@
1-
#/bin/bash
1+
#!/bin/bash
22
set -e
33

44
. ./variables/local.env
55

66
echo Google Cloud initialisation...
77
echo Project: $GCLOUD_PROJECT
88
echo Region: $GCLOUD_REGION
9+
echo Database name: $FIRESTORE_DATABASE
910

1011
gcloud services enable aiplatform.googleapis.com --project=$GCLOUD_PROJECT
1112
gcloud services enable firestore.googleapis.com --project=$GCLOUD_PROJECT
1213

13-
echo Waiting 20s for Firestore API to become available...
14-
sleep 20s
15-
set -x
16-
gcloud firestore databases create --location=$GCLOUD_REGION --project=$GCLOUD_PROJECT
14+
echo "Waiting for Firestore API to become available..."
15+
sleep 10
16+
while ! gcloud firestore databases list --project=$GCLOUD_PROJECT > /dev/null 2>&1; do
17+
echo "Firestore API not yet available. Retrying in 5 seconds..."
18+
sleep 5
19+
done
20+
echo "Firestore API is available. Creating database and indexes..."
21+
22+
gcloud firestore databases create --database="$FIRESTORE_DATABASE" --location=$GCLOUD_REGION --project=$GCLOUD_PROJECT
23+
24+
gcloud firestore indexes composite create \
25+
--project=$GCLOUD_PROJECT \
26+
--database="$FIRESTORE_DATABASE" \
27+
--collection-group="AgentContext" \
28+
--field-config="field-path=user,order=ascending" \
29+
--field-config="field-path=lastUpdate,order=descending" \
30+
--field-config="field-path=__name__,order=descending"
31+
32+
gcloud firestore indexes composite create \
33+
--project=$GCLOUD_PROJECT \
34+
--database="$FIRESTORE_DATABASE" \
35+
--collection-group="Chats" \
36+
--field-config="field-path=userId,order=ascending" \
37+
--field-config="field-path=updatedAt,order=descending" \
38+
--field-config="field-path=__name__,order=descending"
39+
40+
gcloud firestore indexes composite create \
41+
--project=$GCLOUD_PROJECT \
42+
--database="$FIRESTORE_DATABASE" \
43+
--collection-group="LlmCall" \
44+
--field-config="field-path=agentId,order=ascending" \
45+
--field-config="field-path=requestTime,order=descending" \
46+
--field-config="field-path=__name__,order=descending"
47+
48+
echo "Done"

0 commit comments

Comments
 (0)